@@ -240,6 +240,219 @@ const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version
240240});
241241```
242242
243+ ## Account Manager Operations
244+
245+ The SDK provides a unified client for managing users, roles, and organizations through the Account Manager API.
246+
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):
256+
257+ ``` typescript
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' ;
306+ import { OAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
307+
308+ // Create Account Manager client with client credentials OAuth
309+ const auth = new OAuthStrategy ({
310+ clientId: ' your-client-id' ,
311+ clientSecret: ' your-client-secret' ,
312+ });
313+
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 (
352+ { accountManagerHost: ' account.demandware.com' },
353+ auth ,
354+ );
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 );
365+
366+ // List users with pagination
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' );
371+
372+ // Get user with expanded organizations and roles
373+ const userExpanded = await client .getUser (' user-id' , [' organizations' , ' roles' ]);
374+
375+ // Create a new user
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' ,
382+ });
383+
384+ // Update a user
385+ await client .updateUser (' user-id' , { firstName: ' Jane' });
386+
387+ // Grant a role to a user
388+ await client .grantRole (' user-id' , ' bm-admin' , ' tenant1,tenant2' ); // Optional tenant filter
389+
390+ // Revoke a role from a user
391+ await client .revokeRole (' user-id' , ' bm-admin' , ' tenant1' ); // Optional: remove specific scope
392+
393+ // Reset user to INITIAL state
394+ await client .resetUser (' user-id' );
395+
396+ // Delete (disable) a user
397+ await client .deleteUser (' user-id' );
398+ ```
399+
400+ ### Role Operations
401+
402+ ``` typescript
403+ import { createAccountManagerClient } from ' @salesforce/b2c-tooling-sdk/clients' ;
404+ import { ImplicitOAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
405+
406+ const auth = new ImplicitOAuthStrategy ({ clientId: ' your-client-id' });
407+ const client = createAccountManagerClient ({}, auth );
408+
409+ // Get role details by ID
410+ const role = await client .getRole (' bm-admin' );
411+
412+ // List all roles with pagination
413+ const roles = await client .listRoles ({ size: 25 , page: 0 });
414+
415+ // List roles filtered by target type
416+ const userRoles = await client .listRoles ({
417+ size: 25 ,
418+ page: 0 ,
419+ roleTargetType: ' User' ,
420+ });
421+ ```
422+
423+ ### Organization Operations
424+
425+ ``` typescript
426+ import { createAccountManagerClient } from ' @salesforce/b2c-tooling-sdk/clients' ;
427+ import { ImplicitOAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
428+
429+ const auth = new ImplicitOAuthStrategy ({ clientId: ' your-client-id' });
430+ const client = createAccountManagerClient ({}, auth );
431+
432+ // Get organization by ID
433+ const org = await client .getOrg (' org-123' );
434+
435+ // Get organization by name
436+ const orgByName = await client .getOrgByName (' My Organization' );
437+
438+ // List organizations with pagination
439+ const orgs = await client .listOrgs ({ size: 25 , page: 0 });
440+
441+ // List all organizations (uses max page size of 5000)
442+ const allOrgs = await client .listOrgs ({ all: true });
443+
444+ // Get audit logs for an organization
445+ const auditLogs = await client .getOrgAuditLogs (' org-123' );
446+ ```
447+
448+ ### Required Permissions
449+
450+ Account Manager operations require:
451+ - OAuth client with ` sfcc.accountmanager.user.manage ` scope
452+ - 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**
455+
243456## Logging
244457
245458Configure logging for debugging HTTP requests:
0 commit comments