Skip to content

Commit 040fb96

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

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
@@ -215,158 +215,216 @@ const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version
215215

216216
## Account Manager Operations
217217

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

220-
### User Management
220+
### Authentication
221+
222+
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.
223+
224+
For CI/CD and automation, you can also use **OAuth client credentials flow** (requires both client ID and secret).
225+
226+
### Unified Client (Recommended)
227+
228+
The recommended approach is to use the unified `createAccountManagerClient` which provides access to all Account Manager APIs (users, roles, and organizations):
221229

222230
```typescript
223-
import {
224-
listUsers,
225-
getUserByLogin,
226-
createUser,
227-
updateUser,
228-
deleteUser,
229-
resetUser,
230-
grantRole,
231-
revokeRole,
232-
} from '@salesforce/b2c-tooling-sdk/operations/users';
233-
import {createAccountManagerUsersClient} from '@salesforce/b2c-tooling-sdk/clients';
231+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
232+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
233+
234+
// Create Account Manager client with implicit OAuth (opens browser for login)
235+
const auth = new ImplicitOAuthStrategy({
236+
clientId: 'your-client-id',
237+
// No clientSecret needed for implicit flow
238+
});
239+
240+
const client = createAccountManagerClient(
241+
{ accountManagerHost: 'account.demandware.com' },
242+
auth,
243+
);
244+
245+
// Users API
246+
const users = await client.listUsers({ size: 25, page: 0 });
247+
const user = await client.getUser('user-id');
248+
const userByLogin = await client.findUserByLogin('user@example.com');
249+
await client.createUser({
250+
mail: 'newuser@example.com',
251+
firstName: 'John',
252+
lastName: 'Doe',
253+
organizations: ['org-id'],
254+
primaryOrganization: 'org-id',
255+
});
256+
await client.updateUser('user-id', { firstName: 'Jane' });
257+
await client.grantRole('user-id', 'bm-admin', 'tenant1,tenant2');
258+
await client.revokeRole('user-id', 'bm-admin', 'tenant1');
259+
await client.resetUser('user-id');
260+
await client.deleteUser('user-id');
261+
262+
// Roles API
263+
const roles = await client.listRoles({ size: 20, page: 0 });
264+
const role = await client.getRole('bm-admin');
265+
266+
// Organizations API
267+
const orgs = await client.listOrgs({ size: 25, page: 0 });
268+
const org = await client.getOrg('org-id');
269+
const orgByName = await client.getOrgByName('My Organization');
270+
const auditLogs = await client.getOrgAuditLogs('org-id');
271+
```
272+
273+
### Client Credentials Flow (Alternative)
274+
275+
For automation and CI/CD, you can use client credentials flow:
276+
277+
```typescript
278+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
234279
import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
235280

236-
// Create Account Manager client
281+
// Create Account Manager client with client credentials OAuth
237282
const auth = new OAuthStrategy({
238283
clientId: 'your-client-id',
239284
clientSecret: 'your-client-secret',
240285
});
241286

242-
const client = createAccountManagerUsersClient(
287+
const client = createAccountManagerClient(
288+
{ accountManagerHost: 'account.demandware.com' },
289+
auth,
290+
);
291+
292+
// Use the unified client as shown above
293+
```
294+
295+
### Individual Clients
296+
297+
If you only need access to a specific API, you can create individual clients:
298+
299+
```typescript
300+
import {
301+
createAccountManagerUsersClient,
302+
createAccountManagerRolesClient,
303+
createAccountManagerOrgsClient,
304+
} from '@salesforce/b2c-tooling-sdk/clients';
305+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
306+
307+
const auth = new ImplicitOAuthStrategy({
308+
clientId: 'your-client-id',
309+
});
310+
311+
// Users client
312+
const usersClient = createAccountManagerUsersClient(
313+
{ accountManagerHost: 'account.demandware.com' },
314+
auth,
315+
);
316+
317+
// Roles client
318+
const rolesClient = createAccountManagerRolesClient(
319+
{ accountManagerHost: 'account.demandware.com' },
320+
auth,
321+
);
322+
323+
// Organizations client
324+
const orgsClient = createAccountManagerOrgsClient(
243325
{ accountManagerHost: 'account.demandware.com' },
244326
auth,
245327
);
328+
```
329+
330+
### User Operations
331+
332+
```typescript
333+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
334+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
335+
336+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
337+
const client = createAccountManagerClient({}, auth);
246338

247339
// List users with pagination
248-
const users = await listUsers(client, { size: 25, page: 0 });
340+
const users = await client.listUsers({ size: 25, page: 0 });
341+
342+
// Get user by email/login
343+
const user = await client.findUserByLogin('user@example.com');
249344

250-
// Get user by email
251-
const user = await getUserByLogin(client, 'user@example.com');
345+
// Get user with expanded organizations and roles
346+
const userExpanded = await client.getUser('user-id', ['organizations', 'roles']);
252347

253348
// Create a new user
254-
const newUser = await createUser(client, {
255-
user: {
256-
mail: 'newuser@example.com',
257-
firstName: 'John',
258-
lastName: 'Doe',
259-
organizations: ['org-id'],
260-
primaryOrganization: 'org-id',
261-
},
349+
const newUser = await client.createUser({
350+
mail: 'newuser@example.com',
351+
firstName: 'John',
352+
lastName: 'Doe',
353+
organizations: ['org-id'],
354+
primaryOrganization: 'org-id',
262355
});
263356

264357
// Update a user
265-
await updateUser(client, {
266-
userId: user.id!,
267-
changes: { firstName: 'Jane' },
268-
});
358+
await client.updateUser('user-id', { firstName: 'Jane' });
269359

270360
// Grant a role to a user
271-
await grantRole(client, {
272-
userId: user.id!,
273-
role: 'bm-admin',
274-
scope: 'tenant1,tenant2', // Optional tenant filter
275-
});
361+
await client.grantRole('user-id', 'bm-admin', 'tenant1,tenant2'); // Optional tenant filter
276362

277363
// Revoke a role from a user
278-
await revokeRole(client, {
279-
userId: user.id!,
280-
role: 'bm-admin',
281-
scope: 'tenant1', // Optional: remove specific scope
282-
});
364+
await client.revokeRole('user-id', 'bm-admin', 'tenant1'); // Optional: remove specific scope
283365

284366
// Reset user to INITIAL state
285-
await resetUser(client, user.id!);
367+
await client.resetUser('user-id');
286368

287369
// Delete (disable) a user
288-
await deleteUser(client, user.id!);
370+
await client.deleteUser('user-id');
289371
```
290372

291-
### Role Management
373+
### Role Operations
292374

293375
```typescript
294-
import {
295-
createAccountManagerRolesClient,
296-
getRole,
297-
listRoles,
298-
} from '@salesforce/b2c-tooling-sdk/operations/roles';
299-
import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
376+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
377+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
300378

301-
// Create Account Manager Roles client
302-
const auth = new OAuthStrategy({
303-
clientId: 'your-client-id',
304-
clientSecret: 'your-client-secret',
305-
});
306-
307-
const client = createAccountManagerRolesClient(
308-
{ accountManagerHost: 'account.demandware.com' },
309-
auth,
310-
);
379+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
380+
const client = createAccountManagerClient({}, auth);
311381

312382
// Get role details by ID
313-
const role = await getRole(client, 'bm-admin');
383+
const role = await client.getRole('bm-admin');
314384

315385
// List all roles with pagination
316-
const roles = await listRoles(client, { size: 25, page: 0 });
386+
const roles = await client.listRoles({ size: 25, page: 0 });
317387

318388
// List roles filtered by target type
319-
const userRoles = await listRoles(client, {
389+
const userRoles = await client.listRoles({
320390
size: 25,
321391
page: 0,
322392
roleTargetType: 'User',
323393
});
324394
```
325395

326-
### Organization Management
396+
### Organization Operations
327397

328398
```typescript
329-
import {
330-
createAccountManagerOrgsClient,
331-
getOrg,
332-
getOrgByName,
333-
listOrgs,
334-
getOrgAuditLogs,
335-
} from '@salesforce/b2c-tooling-sdk/operations/orgs';
336-
import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
399+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
400+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
337401

338-
// Create Account Manager Organizations client
339-
const auth = new OAuthStrategy({
340-
clientId: 'your-client-id',
341-
clientSecret: 'your-client-secret',
342-
});
343-
344-
const client = createAccountManagerOrgsClient(
345-
{ accountManagerHost: 'account.demandware.com' },
346-
auth,
347-
);
402+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
403+
const client = createAccountManagerClient({}, auth);
348404

349405
// Get organization by ID
350-
const org = await getOrg(client, 'org-123');
406+
const org = await client.getOrg('org-123');
351407

352408
// Get organization by name
353-
const orgByName = await getOrgByName(client, 'My Organization');
409+
const orgByName = await client.getOrgByName('My Organization');
354410

355411
// List organizations with pagination
356-
const orgs = await listOrgs(client, { size: 25, page: 0 });
412+
const orgs = await client.listOrgs({ size: 25, page: 0 });
357413

358414
// List all organizations (uses max page size of 5000)
359-
const allOrgs = await listOrgs(client, { all: true });
415+
const allOrgs = await client.listOrgs({ all: true });
360416

361417
// Get audit logs for an organization
362-
const auditLogs = await getOrgAuditLogs(client, 'org-123');
418+
const auditLogs = await client.getOrgAuditLogs('org-123');
363419
```
364420

365421
### Required Permissions
366422

367423
Account Manager operations require:
368424
- OAuth client with `sfcc.accountmanager.user.manage` scope
369425
- Account Manager hostname configuration
426+
- For implicit flow: roles configured on your **user account**
427+
- For client credentials flow: roles configured on the **API client**
370428

371429
## Logging
372430

0 commit comments

Comments
 (0)