Skip to content

Commit afff2e1

Browse files
@W-20893693: Adding AM topic with users, role and org subtopics
1 parent 7536567 commit afff2e1

1 file changed

Lines changed: 144 additions & 86 deletions

File tree

docs/api-readme.md

Lines changed: 144 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -242,158 +242,216 @@ const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version
242242

243243
## Account Manager Operations
244244

245-
The SDK provides operations for managing users, roles, and organizations.
245+
The SDK provides a unified client for managing users, roles, and organizations through the Account Manager API.
246246

247-
### User Management
247+
### Authentication
248+
249+
Account Manager operations use **OAuth implicit flow** by default, which opens a browser for interactive authentication. This is ideal for development and manual operations where you want to use roles assigned to your user account.
250+
251+
For CI/CD and automation, you can also use **OAuth client credentials flow** (requires both client ID and secret).
252+
253+
### Unified Client (Recommended)
254+
255+
The recommended approach is to use the unified `createAccountManagerClient` which provides access to all Account Manager APIs (users, roles, and organizations):
248256

249257
```typescript
250-
import {
251-
listUsers,
252-
getUserByLogin,
253-
createUser,
254-
updateUser,
255-
deleteUser,
256-
resetUser,
257-
grantRole,
258-
revokeRole,
259-
} from '@salesforce/b2c-tooling-sdk/operations/users';
260-
import {createAccountManagerUsersClient} from '@salesforce/b2c-tooling-sdk/clients';
258+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
259+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
260+
261+
// Create Account Manager client with implicit OAuth (opens browser for login)
262+
const auth = new ImplicitOAuthStrategy({
263+
clientId: 'your-client-id',
264+
// No clientSecret needed for implicit flow
265+
});
266+
267+
const client = createAccountManagerClient(
268+
{ accountManagerHost: 'account.demandware.com' },
269+
auth,
270+
);
271+
272+
// Users API
273+
const users = await client.listUsers({ size: 25, page: 0 });
274+
const user = await client.getUser('user-id');
275+
const userByLogin = await client.findUserByLogin('user@example.com');
276+
await client.createUser({
277+
mail: 'newuser@example.com',
278+
firstName: 'John',
279+
lastName: 'Doe',
280+
organizations: ['org-id'],
281+
primaryOrganization: 'org-id',
282+
});
283+
await client.updateUser('user-id', { firstName: 'Jane' });
284+
await client.grantRole('user-id', 'bm-admin', 'tenant1,tenant2');
285+
await client.revokeRole('user-id', 'bm-admin', 'tenant1');
286+
await client.resetUser('user-id');
287+
await client.deleteUser('user-id');
288+
289+
// Roles API
290+
const roles = await client.listRoles({ size: 20, page: 0 });
291+
const role = await client.getRole('bm-admin');
292+
293+
// Organizations API
294+
const orgs = await client.listOrgs({ size: 25, page: 0 });
295+
const org = await client.getOrg('org-id');
296+
const orgByName = await client.getOrgByName('My Organization');
297+
const auditLogs = await client.getOrgAuditLogs('org-id');
298+
```
299+
300+
### Client Credentials Flow (Alternative)
301+
302+
For automation and CI/CD, you can use client credentials flow:
303+
304+
```typescript
305+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
261306
import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
262307

263-
// Create Account Manager client
308+
// Create Account Manager client with client credentials OAuth
264309
const auth = new OAuthStrategy({
265310
clientId: 'your-client-id',
266311
clientSecret: 'your-client-secret',
267312
});
268313

269-
const client = createAccountManagerUsersClient(
314+
const client = createAccountManagerClient(
315+
{ accountManagerHost: 'account.demandware.com' },
316+
auth,
317+
);
318+
319+
// Use the unified client as shown above
320+
```
321+
322+
### Individual Clients
323+
324+
If you only need access to a specific API, you can create individual clients:
325+
326+
```typescript
327+
import {
328+
createAccountManagerUsersClient,
329+
createAccountManagerRolesClient,
330+
createAccountManagerOrgsClient,
331+
} from '@salesforce/b2c-tooling-sdk/clients';
332+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
333+
334+
const auth = new ImplicitOAuthStrategy({
335+
clientId: 'your-client-id',
336+
});
337+
338+
// Users client
339+
const usersClient = createAccountManagerUsersClient(
340+
{ accountManagerHost: 'account.demandware.com' },
341+
auth,
342+
);
343+
344+
// Roles client
345+
const rolesClient = createAccountManagerRolesClient(
346+
{ accountManagerHost: 'account.demandware.com' },
347+
auth,
348+
);
349+
350+
// Organizations client
351+
const orgsClient = createAccountManagerOrgsClient(
270352
{ accountManagerHost: 'account.demandware.com' },
271353
auth,
272354
);
355+
```
356+
357+
### User Operations
358+
359+
```typescript
360+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
361+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
362+
363+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
364+
const client = createAccountManagerClient({}, auth);
273365

274366
// List users with pagination
275-
const users = await listUsers(client, { size: 25, page: 0 });
367+
const users = await client.listUsers({ size: 25, page: 0 });
368+
369+
// Get user by email/login
370+
const user = await client.findUserByLogin('user@example.com');
276371

277-
// Get user by email
278-
const user = await getUserByLogin(client, 'user@example.com');
372+
// Get user with expanded organizations and roles
373+
const userExpanded = await client.getUser('user-id', ['organizations', 'roles']);
279374

280375
// Create a new user
281-
const newUser = await createUser(client, {
282-
user: {
283-
mail: 'newuser@example.com',
284-
firstName: 'John',
285-
lastName: 'Doe',
286-
organizations: ['org-id'],
287-
primaryOrganization: 'org-id',
288-
},
376+
const newUser = await client.createUser({
377+
mail: 'newuser@example.com',
378+
firstName: 'John',
379+
lastName: 'Doe',
380+
organizations: ['org-id'],
381+
primaryOrganization: 'org-id',
289382
});
290383

291384
// Update a user
292-
await updateUser(client, {
293-
userId: user.id!,
294-
changes: { firstName: 'Jane' },
295-
});
385+
await client.updateUser('user-id', { firstName: 'Jane' });
296386

297387
// Grant a role to a user
298-
await grantRole(client, {
299-
userId: user.id!,
300-
role: 'bm-admin',
301-
scope: 'tenant1,tenant2', // Optional tenant filter
302-
});
388+
await client.grantRole('user-id', 'bm-admin', 'tenant1,tenant2'); // Optional tenant filter
303389

304390
// Revoke a role from a user
305-
await revokeRole(client, {
306-
userId: user.id!,
307-
role: 'bm-admin',
308-
scope: 'tenant1', // Optional: remove specific scope
309-
});
391+
await client.revokeRole('user-id', 'bm-admin', 'tenant1'); // Optional: remove specific scope
310392

311393
// Reset user to INITIAL state
312-
await resetUser(client, user.id!);
394+
await client.resetUser('user-id');
313395

314396
// Delete (disable) a user
315-
await deleteUser(client, user.id!);
397+
await client.deleteUser('user-id');
316398
```
317399

318-
### Role Management
400+
### Role Operations
319401

320402
```typescript
321-
import {
322-
createAccountManagerRolesClient,
323-
getRole,
324-
listRoles,
325-
} from '@salesforce/b2c-tooling-sdk/operations/roles';
326-
import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
403+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
404+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
327405

328-
// Create Account Manager Roles client
329-
const auth = new OAuthStrategy({
330-
clientId: 'your-client-id',
331-
clientSecret: 'your-client-secret',
332-
});
333-
334-
const client = createAccountManagerRolesClient(
335-
{ accountManagerHost: 'account.demandware.com' },
336-
auth,
337-
);
406+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
407+
const client = createAccountManagerClient({}, auth);
338408

339409
// Get role details by ID
340-
const role = await getRole(client, 'bm-admin');
410+
const role = await client.getRole('bm-admin');
341411

342412
// List all roles with pagination
343-
const roles = await listRoles(client, { size: 25, page: 0 });
413+
const roles = await client.listRoles({ size: 25, page: 0 });
344414

345415
// List roles filtered by target type
346-
const userRoles = await listRoles(client, {
416+
const userRoles = await client.listRoles({
347417
size: 25,
348418
page: 0,
349419
roleTargetType: 'User',
350420
});
351421
```
352422

353-
### Organization Management
423+
### Organization Operations
354424

355425
```typescript
356-
import {
357-
createAccountManagerOrgsClient,
358-
getOrg,
359-
getOrgByName,
360-
listOrgs,
361-
getOrgAuditLogs,
362-
} from '@salesforce/b2c-tooling-sdk/operations/orgs';
363-
import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
426+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
427+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
364428

365-
// Create Account Manager Organizations client
366-
const auth = new OAuthStrategy({
367-
clientId: 'your-client-id',
368-
clientSecret: 'your-client-secret',
369-
});
370-
371-
const client = createAccountManagerOrgsClient(
372-
{ accountManagerHost: 'account.demandware.com' },
373-
auth,
374-
);
429+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
430+
const client = createAccountManagerClient({}, auth);
375431

376432
// Get organization by ID
377-
const org = await getOrg(client, 'org-123');
433+
const org = await client.getOrg('org-123');
378434

379435
// Get organization by name
380-
const orgByName = await getOrgByName(client, 'My Organization');
436+
const orgByName = await client.getOrgByName('My Organization');
381437

382438
// List organizations with pagination
383-
const orgs = await listOrgs(client, { size: 25, page: 0 });
439+
const orgs = await client.listOrgs({ size: 25, page: 0 });
384440

385441
// List all organizations (uses max page size of 5000)
386-
const allOrgs = await listOrgs(client, { all: true });
442+
const allOrgs = await client.listOrgs({ all: true });
387443

388444
// Get audit logs for an organization
389-
const auditLogs = await getOrgAuditLogs(client, 'org-123');
445+
const auditLogs = await client.getOrgAuditLogs('org-123');
390446
```
391447

392448
### Required Permissions
393449

394450
Account Manager operations require:
395451
- OAuth client with `sfcc.accountmanager.user.manage` scope
396452
- Account Manager hostname configuration
453+
- For implicit flow: roles configured on your **user account**
454+
- For client credentials flow: roles configured on the **API client**
397455

398456
## Logging
399457

0 commit comments

Comments
 (0)