@@ -241,6 +241,219 @@ const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version
241241});
242242```
243243
244+ ## Account Manager Operations
245+
246+ The SDK provides a unified client for managing users, roles, and organizations through the Account Manager API.
247+
248+ ### Authentication
249+
250+ 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.
251+
252+ For CI/CD and automation, you can also use ** OAuth client credentials flow** (requires both client ID and secret).
253+
254+ ### Unified Client (Recommended)
255+
256+ The recommended approach is to use the unified ` createAccountManagerClient ` which provides access to all Account Manager APIs (users, roles, and organizations):
257+
258+ ``` typescript
259+ import { createAccountManagerClient } from ' @salesforce/b2c-tooling-sdk/clients' ;
260+ import { ImplicitOAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
261+
262+ // Create Account Manager client with implicit OAuth (opens browser for login)
263+ const auth = new ImplicitOAuthStrategy ({
264+ clientId: ' your-client-id' ,
265+ // No clientSecret needed for implicit flow
266+ });
267+
268+ const client = createAccountManagerClient (
269+ { accountManagerHost: ' account.demandware.com' },
270+ auth ,
271+ );
272+
273+ // Users API
274+ const users = await client .listUsers ({ size: 25 , page: 0 });
275+ const user = await client .getUser (' user-id' );
276+ const userByLogin = await client .findUserByLogin (' user@example.com' );
277+ await client .createUser ({
278+ mail: ' newuser@example.com' ,
279+ firstName: ' John' ,
280+ lastName: ' Doe' ,
281+ organizations: [' org-id' ],
282+ primaryOrganization: ' org-id' ,
283+ });
284+ await client .updateUser (' user-id' , { firstName: ' Jane' });
285+ await client .grantRole (' user-id' , ' bm-admin' , ' tenant1,tenant2' );
286+ await client .revokeRole (' user-id' , ' bm-admin' , ' tenant1' );
287+ await client .resetUser (' user-id' );
288+ await client .deleteUser (' user-id' );
289+
290+ // Roles API
291+ const roles = await client .listRoles ({ size: 20 , page: 0 });
292+ const role = await client .getRole (' bm-admin' );
293+
294+ // Organizations API
295+ const orgs = await client .listOrgs ({ size: 25 , page: 0 });
296+ const org = await client .getOrg (' org-id' );
297+ const orgByName = await client .getOrgByName (' My Organization' );
298+ const auditLogs = await client .getOrgAuditLogs (' org-id' );
299+ ```
300+
301+ ### Client Credentials Flow (Alternative)
302+
303+ For automation and CI/CD, you can use client credentials flow:
304+
305+ ``` typescript
306+ import { createAccountManagerClient } from ' @salesforce/b2c-tooling-sdk/clients' ;
307+ import { OAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
308+
309+ // Create Account Manager client with client credentials OAuth
310+ const auth = new OAuthStrategy ({
311+ clientId: ' your-client-id' ,
312+ clientSecret: ' your-client-secret' ,
313+ });
314+
315+ const client = createAccountManagerClient (
316+ { accountManagerHost: ' account.demandware.com' },
317+ auth ,
318+ );
319+
320+ // Use the unified client as shown above
321+ ```
322+
323+ ### Individual Clients
324+
325+ If you only need access to a specific API, you can create individual clients:
326+
327+ ``` typescript
328+ import {
329+ createAccountManagerUsersClient ,
330+ createAccountManagerRolesClient ,
331+ createAccountManagerOrgsClient ,
332+ } from ' @salesforce/b2c-tooling-sdk/clients' ;
333+ import { ImplicitOAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
334+
335+ const auth = new ImplicitOAuthStrategy ({
336+ clientId: ' your-client-id' ,
337+ });
338+
339+ // Users client
340+ const usersClient = createAccountManagerUsersClient (
341+ { accountManagerHost: ' account.demandware.com' },
342+ auth ,
343+ );
344+
345+ // Roles client
346+ const rolesClient = createAccountManagerRolesClient (
347+ { accountManagerHost: ' account.demandware.com' },
348+ auth ,
349+ );
350+
351+ // Organizations client
352+ const orgsClient = createAccountManagerOrgsClient (
353+ { accountManagerHost: ' account.demandware.com' },
354+ auth ,
355+ );
356+ ```
357+
358+ ### User Operations
359+
360+ ``` typescript
361+ import { createAccountManagerClient } from ' @salesforce/b2c-tooling-sdk/clients' ;
362+ import { ImplicitOAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
363+
364+ const auth = new ImplicitOAuthStrategy ({ clientId: ' your-client-id' });
365+ const client = createAccountManagerClient ({}, auth );
366+
367+ // List users with pagination
368+ const users = await client .listUsers ({ size: 25 , page: 0 });
369+
370+ // Get user by email/login
371+ const user = await client .findUserByLogin (' user@example.com' );
372+
373+ // Get user with expanded organizations and roles
374+ const userExpanded = await client .getUser (' user-id' , [' organizations' , ' roles' ]);
375+
376+ // Create a new user
377+ const newUser = await client .createUser ({
378+ mail: ' newuser@example.com' ,
379+ firstName: ' John' ,
380+ lastName: ' Doe' ,
381+ organizations: [' org-id' ],
382+ primaryOrganization: ' org-id' ,
383+ });
384+
385+ // Update a user
386+ await client .updateUser (' user-id' , { firstName: ' Jane' });
387+
388+ // Grant a role to a user
389+ await client .grantRole (' user-id' , ' bm-admin' , ' tenant1,tenant2' ); // Optional tenant filter
390+
391+ // Revoke a role from a user
392+ await client .revokeRole (' user-id' , ' bm-admin' , ' tenant1' ); // Optional: remove specific scope
393+
394+ // Reset user to INITIAL state
395+ await client .resetUser (' user-id' );
396+
397+ // Delete (disable) a user
398+ await client .deleteUser (' user-id' );
399+ ```
400+
401+ ### Role Operations
402+
403+ ``` typescript
404+ import { createAccountManagerClient } from ' @salesforce/b2c-tooling-sdk/clients' ;
405+ import { ImplicitOAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
406+
407+ const auth = new ImplicitOAuthStrategy ({ clientId: ' your-client-id' });
408+ const client = createAccountManagerClient ({}, auth );
409+
410+ // Get role details by ID
411+ const role = await client .getRole (' bm-admin' );
412+
413+ // List all roles with pagination
414+ const roles = await client .listRoles ({ size: 25 , page: 0 });
415+
416+ // List roles filtered by target type
417+ const userRoles = await client .listRoles ({
418+ size: 25 ,
419+ page: 0 ,
420+ roleTargetType: ' User' ,
421+ });
422+ ```
423+
424+ ### Organization Operations
425+
426+ ``` typescript
427+ import { createAccountManagerClient } from ' @salesforce/b2c-tooling-sdk/clients' ;
428+ import { ImplicitOAuthStrategy } from ' @salesforce/b2c-tooling-sdk/auth' ;
429+
430+ const auth = new ImplicitOAuthStrategy ({ clientId: ' your-client-id' });
431+ const client = createAccountManagerClient ({}, auth );
432+
433+ // Get organization by ID
434+ const org = await client .getOrg (' org-123' );
435+
436+ // Get organization by name
437+ const orgByName = await client .getOrgByName (' My Organization' );
438+
439+ // List organizations with pagination
440+ const orgs = await client .listOrgs ({ size: 25 , page: 0 });
441+
442+ // List all organizations (uses max page size of 5000)
443+ const allOrgs = await client .listOrgs ({ all: true });
444+
445+ // Get audit logs for an organization
446+ const auditLogs = await client .getOrgAuditLogs (' org-123' );
447+ ```
448+
449+ ### Required Permissions
450+
451+ Account Manager operations require:
452+ - OAuth client with ` sfcc.accountmanager.user.manage ` scope
453+ - Account Manager hostname configuration
454+ - For implicit flow: roles configured on your ** user account**
455+ - For client credentials flow: roles configured on the ** API client**
456+
244457## Logging
245458
246459Configure logging for debugging HTTP requests:
0 commit comments