> For the complete documentation index, see [llms.txt](https://docs-en.dydu.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-en.dydu.ai/developers/api-reference/user-management-in-the-bms.md).

# User Management in the BMS

This API lets you create a BMS user account or update an existing account. It is not part of the Swagger interface.

## Create or update a user

* **Address**: `https://<server>/servlet/accounts/update`, replacing `<server>` with the address of your platform.
* **Method**: `GET` or `POST`, with the parameters in the address or in the form.
* **Authentication**: `Authorization` header (see [Authentication](https://docs-en.dydu.ai/developers/api-reference/authentication)). The account used must be an administrator of each bot listed in `rights` and `competencies`.

If the login already exists, the matching account is updated. Otherwise, a new account is created.

| Parameter      | Required | Description                                                                                                                                                                       |
| -------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `login`        | Yes      | Login of the account to create or update. A login is unique.                                                                                                                      |
| `accountId`    | No       | Account identifier. Only enter it to update an existing account.                                                                                                                  |
| `firstName`    | No       | User's first name.                                                                                                                                                                |
| `lastName`     | No       | User's last name.                                                                                                                                                                 |
| `email`        | No       | User's email address.                                                                                                                                                             |
| `password`     | No       | User's password. It must follow the password policy of the platform: at least 16 characters, including an uppercase letter, a lowercase letter, a number and a special character. |
| `language`     | No       | BMS interface language: "fr" or "en" (the names "French" and "English" are also accepted).                                                                                        |
| `rights`       | No       | User's rights per bot, in JSON format. See [Rights and competencies](#rights-and-competencies).                                                                                   |
| `competencies` | No       | User's livechat competencies per bot and per language, in JSON format. See [Rights and competencies](#rights-and-competencies).                                                   |

### Rights and competencies

The `rights` and `competencies` parameters are JSON objects:

* the `type` key sets how the changes are applied:
* `default`: adds the rights or competencies given, without removing the others;
* `merge`: replaces the user's rights or competencies, and removes the ones that are not given;
* each other key is the identifier of a bot.

For `rights`, the value is the name of the rights groups, separated by commas:

```
{
  "type": "default",
  "9fbd59f2-bf91-4aab-bee1-a36c2a3ebece": "Group1,Group2",
  "6ae11dd2-c322-4177-aab0-9c6754cf1bcd": "Writer"
}
```

For `competencies`, the value gives the competencies per language, separated by commas:

```
{
  "type": "default",
  "9fbd59f2-bf91-4aab-bee1-a36c2a3ebece": { "fr": "Competence1,Competence2", "en": "Competency1" }
}
```

The available rights and competencies depend on the bot.

### Example

```
curl -X POST "https://<server>/servlet/accounts/update" \
  -H "Authorization: Basic ZGVtb0BkeWR1LmFpOk15UGFzc3dvcmQ=" \
  --data-urlencode "login=john.smith@example.com" \
  --data-urlencode "firstName=John" \
  --data-urlencode "lastName=Smith" \
  --data-urlencode "language=en" \
  --data-urlencode 'rights={"type":"default","9fbd59f2-bf91-4aab-bee1-a36c2a3ebece":"Writer"}'
```

Response:

```
{"status":"success","updatedAccount":{...}}
```

If an error occurs, the API returns a 400 code, or 401 with the "Invalid authentication" message if authentication is refused.
