Automated user management

To make it easier to work with multiple user accounts at once, you can automate user account management using any of the following options.

Note

In Sitecore Content Hub, each user is uniquely identified with a username, a password, and a profile. Together with other settings, the profile determines which tasks the user can perform, what data the user can see, and what the user can do with the data.

REST API

You can automate user management using the REST API.

  • Add a user with username SampleUser:

    • Method: POST

    • URL: https://my-instance.com/api/entitydefinitions/User/entities

    • Request body:

      RequestResponse
      
      {
       "properties":{
        "Username":"SampleUser",
        "UserGroupConfiguration":null,
        "HasToken":null,
        "EmailConfirmationPending":null,
        "LockoutEndDate":null,
        "AccessFailedCount":null,
        "IsRestricted":null,
        "LastLoginDateTime":null,
        "LastPasswordChangeDateTime":null
       },
       "entitydefinition":{
        "href":"https://my-instance.com/api/entitydefinitions/User"
       },
      }
      
      
    • Example response:

      RequestResponse
      
      201 created
      Content-Length: content length
      Location : https://my-instance.com/api/entities/10657
      
      
  • Delete a user with ID '10657':

    • Method: DELETE

    • URL: https://my-instance.com/api/entities/10657

    • No request body.

Note

For more information, see User Resource.

Scripting API

You can also automate user creation and deletion using the Users client in the Scripting API.

  • Add a user:

    RequestResponse
    
    IEntity user = await MClient.EntityFactory.CreateAsync(Constants.User.DefinitionName);
    //Add code to configure the user parameters
    await MClient.Entities.SaveAsync(user);
    
    
  • Delete a user:

    RequestResponse
    
    IEntity user = await MClient.Users.GetUserAsync("username");
    await MClient.Entities.DeleteAsync(user.Id);
    
    
Note

For more information, see the Users client documentation.

Web SDK

User creation, amendment, and deletion are also possible through the Web SDK via the Users client.

  • Add a user:

    RequestResponse
    
    IEntity user = await MClient.EntityFactory.CreateAsync(Constants.User.DefinitionName);
    //Add code to configure the user parameters
    await MClient.Entities.SaveAsync(user);
    
    
  • Delete a user:

    RequestResponse
    
    IEntity user = await MClient.Users.GetUserAsync("username");
    await MClient.Entities.DeleteAsync(user.Id);
    
    
Note

For further information, see the Users client documentation.

Do you have some feedback for us?

If you have suggestions for improving this article,