# Create, update and delete users via API

Importing or modifying users allows you to automate the management of your users to:

* create your users in bulk,
* synchronise your users between applications (user provisioning),
* automate the creation of a user according to your needs,
* update user information (username, password, group, ...),
* modify the configuration of your users' communication channels\
  etc.

## Pre-requisite: recovery of your GraphQL API keys

API authentication uses temporary and revocable access keys.

Please note that the lifetime of the key is 24 hours

You can generate an access key by calling the url mentioned in [this link](https://developers.iadvize.com/documentation/graphql-api#graphql-api) with a user email and a password. [See more ](https://docs.iadvize.dev/technologies/graphql-api/authentication)about GraphQL authentification.

## Create a user

### Description of mutation field

To create a new user via the [GraphQL API](https://developers.iadvize.com/documentation/graphql-api#graphql-api), you can enter all the fields below - only those with a star are required:

| Informations                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Descriptions                                                                                                                                                                                                                                                                                                                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **avatar**\*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Avatar’s URL                                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><strong>channels</strong></p><ul><li><p><strong>callConfiguration</strong></p><ul><li>clickToCallPhoneNumber</li><li>hasPriorityOnCall\*</li><li>isAlwaysAskForNumber\*</li><li>isEnabled\*</li><li>respondFrom\*</li></ul><p><strong>x</strong> CLICK\_TO\_CALL\_NUMBER</p><p><strong>x</strong> DESK</p></li><li><p><strong>chatConfiguration</strong></p><ul><li>hasPriorityOnChat\*</li><li>isAllowChatToVideo\*</li><li>isEnabled\*</li><li>isSimultaneousCallAllowed</li><li>numberOfSlots\*</li></ul></li><li><p><strong>thirdPartyConfiguration</strong></p><ul><li>isEnabled\*</li><li>numberOfSlots\*</li></ul></li><li><p><strong>videoConfiguration</strong></p><ul><li>hasPriorityOnVideo\*</li><li>isEnabled\*</li></ul></li></ul> | Configuration of user communication channel(s)                                                                                                                                                                                                                                                                                                                                                                |
| <p><strong>countryPreferences\*</strong></p><ul><li><p><strong>dateFormat</strong></p><ul><li>DMY</li><li>MDY</li><li>YMD</li></ul></li><li><strong>interfaceLanguage</strong></li><li><em><strong>languages</strong></em></li><li><p><strong>timeFormat</strong></p><ul><li>CLASSIC</li><li>MERIDIAN</li></ul></li><li><strong>timezone</strong></li></ul>                                                                                                                                                                                                                                                                                                                                                                                         | <p>Date format:</p><ul><li>DMY<br>Example: 31/12/2024</li><li>MDY<br>Example: 12/31/2024</li><li>YMD<br>Example: 2023-12-31</li></ul><p>User’s interface language (ISO format)</p><p>User’s language (ISO format)</p><p>Time format:</p><ul><li>CLASSIC<br>Example: 13:55</li><li>MERIDIAN<br>Example: 01:55 PM</li></ul><p>User’s timezone:</p><p>Example: "Europe/Paris"</p>                                |
| **email\***                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | User email                                                                                                                                                                                                                                                                                                                                                                                                    |
| **externalId**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Id representing the user in the client’s system                                                                                                                                                                                                                                                                                                                                                               |
| **firstName**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | User first name                                                                                                                                                                                                                                                                                                                                                                                               |
| **groupId**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Groups are used to partition information and user exchanges in the iAdvize administration. For more information on user groups, please see the following documentation: [Help Center - Use the user groups](https://help.iadvize.com/hc/en-gb/articles/203280696-Use-the-user-groups)                                                                                                                         |
| **lastName\***                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | User last name                                                                                                                                                                                                                                                                                                                                                                                                |
| **password\***                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | User password (that he will change on first connection)                                                                                                                                                                                                                                                                                                                                                       |
| **projectIds\***                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <p>Projects assigned to the user, determining which projects the user can manage conversations for</p><p>roleIds\*</p>                                                                                                                                                                                                                                                                                        |
| **roleIds\***                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | <p>If you don’t know which role to pick, please see the following documentation: <a href="https://help.iadvize.com/hc/en/articles/115006327848">Help Center - Choose the right role for the user account</a></p><ul><li>2 ⇔ operator</li><li>3 ⇔ manager</li><li>4 ⇔ admin</li><li>5 ⇔ expert</li><li>6 ⇔ developer</li><li>7 ⇔ bot</li></ul>                                                                 |
| **skillIds**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Skills can be managed after user creation through `userSkillsAdd`, `userSkillsRemove`, `userSkillsSet` mutations. The user's skills can be used to determine which routing group the user will be a member of. For more information on creating and using skills, please see the following documentation: [Help Center - Use the skills](https://help.iadvize.com/hc/en-gb/articles/203444283-Use-the-skills) |
| **userName\***                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Displayed under the user’s avatar in the chatbox                                                                                                                                                                                                                                                                                                                                                              |

### Examples of user creation

{% tabs %}
{% tab title="Operateur account (roleId = 2)" %}

```graphql

mutation MyMutation {
  userCreate(input: {lastName: "Vergez", email: "mvergez@test.com", password: "iAdvize123!", roleId: 6, userName: "Matt", avatar: "https://ha.iadvize.com/admin/public/images/account/profile-pic-icon.svg", projectIds: 6661, firstName: "Matt", countryPreferences: {interfaceLanguage: fr, languages: "fr"}}) {
    user {
      avatarUrl
      email
      firstName
      id
      lastName
      projects {
        edges {
          node {
            id
            name
          }
        }
      }
      userName
      createdAt
      deletedAt
      avatar
      interfaceLanguage
      isDeleted
      spokenLanguages
      pseudo
    }
    userErrors {
      ... on UserError {
        __typename
        message
      }
    }
  }
}


```

{% endtab %}

{% tab title="Developer account (roleId = 6)" %}

```graphql
mutation MyMutation {
  userCreate(input: {lastName: "Vergez", email: "mvergez@test.com", password: "iAdvize123!", roleId: 6, userName: "Matt", avatar: "https://ha.iadvize.com/admin/public/images/account/profile-pic-icon.svg", projectIds: 6661, firstName: "Matt", countryPreferences: {interfaceLanguage: fr, languages: "fr"}}) {
    user {
      avatarUrl
      email
      firstName
      id
      lastName
      projects {
        edges {
          node {
            id
            name
          }
        }
      }
      userName
      createdAt
      deletedAt
      avatar
      interfaceLanguage
      isDeleted
      spokenLanguages
      pseudo
    }
    userErrors {
      ... on UserError {
        __typename
        message
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

## Update a user

Use the mutation "`userUpdate`" instead of "`userCreate`". All the fields in the [Create a user](#create-a-user) part are editable except for the userId field. However, this field is mandatory in the mutation to ensure that the correct user is modified.

{% hint style="info" %}
In this mutation, only the fields to be modified must be filled in. Fields that are not filled in won’t be updated.
{% endhint %}

## Delete a user

You will need the **userId in 6 digit format**.

Here is an example of a GraphQL query to delete the user with userId XXXXXX:

```graphql
mutation MyMutation {
  userDelete(input: {userId: XXXXXX}) {
    userErrors {
      ... on UserHasOngoingConversationsUserDeleteError {
        __typename
        message
      }
    }
    userId
  }
}
```

If all goes well, here's the response you'll get from the GraphQL API:

```json
{
  "data": {
    "userDelete": {
      "userErrors": null,
      "userId": XXXXXX
    }
  }
}
```
