# Create User

Use the `createUser` mutation to create a new account for an end-user on your organization's account.

{% hint style="info" %}
**Anonymization:** Kindly be aware that the essential fields for creating a user profile include the name and email. If you prefer a completely anonymous format, you are welcome to provide a generic user name, like "\<ORGANIZATION\_NAME> User," and a distinct email address, such as "\<USER\_ID>@\<ORGANIZATION\_DOMAIN>".
{% endhint %}

## **Arguments**

<table data-header-hidden><thead><tr><th>Argument</th><th width="150">Required</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>Argument</strong></td><td><strong>Required</strong></td><td><strong>Type</strong></td><td><strong>Description</strong></td></tr><tr><td><code>name</code></td><td>True</td><td>String</td><td>User's name</td></tr><tr><td><code>email</code></td><td>True</td><td>String</td><td>User's email</td></tr><tr><td><code>phone</code></td><td>False</td><td>String</td><td>User's phone</td></tr><tr><td><code>password</code></td><td>False</td><td>String</td><td>Set up a user's password</td></tr><tr><td><code>program</code></td><td>False</td><td>String</td><td>Include the database ID of the Program. If this parameter is not sent, the program can be later assgined by using the <a href="https://docs.suggestic.com/graphql/query/mutations/user-profile/set-program"><code>updateUserProgram</code></a> mutation</td></tr><tr><td><code>restrictions</code></td><td>False</td><td>String</td><td>Restriction Base-64 ID. If this parameter is not sent, restrictions can be later assigned by using the <a href="https://docs.suggestic.com/graphql/query/mutations/user-profile/profilerestrictionsupdate"><code>profileRestrictionsUpdate</code></a> mutation</td></tr><tr><td><code>emailPasswordNotification</code></td><td>False</td><td>Boolean</td><td>Notification sent via email to set up a user's password</td></tr><tr><td><code>subscription</code></td><td>False</td><td>ID</td><td>Base-64 subscription ID which will be assigned to the created user.</td></tr></tbody></table>

## Available Fields

The following fields will be displayed in the response:

| Field     | Type                                                           | Description                                                                        |
| --------- | -------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| `success` | string                                                         | **True** if the user has been created successfully. Otherwise, **False**           |
| `message` | string                                                         | Description of the result                                                          |
| `user`    | [user](https://docs.suggestic.com/graphql/objects/common/user) | A structured version of user information. It contains `id` and `databaseId` fields |

## **Examples**

### GraphQL

{% tabs %}
{% tab title="Mutation" %}

```graphql
mutation {
  createUser(
    name: "Ernesto"
    email: "ernesto@suggestic.com"
  ) {
    success
    message
    user {
      id
      databaseId
    }
  }
}

```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "data": {
    "createUser": {
      "success": true,
      "message": "User created",
      "user": {
        "id": "VXNlcjpWWE5sY2pvMk16QXlORE5oTWkxaVl6Rm1MVFEzWkdNdFlqbGtOaTAyTldOak1qa3lOMkZrWW1NPQ==",
        "databaseId": "630243a2-bc1f-47dc-b9d6-65cc2927adbc"
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

### Setup a user's password

The following example creates a user and sets up the password without sending an email notification.

{% tabs %}
{% tab title="Request" %}

```graphql
mutation {
  createUser(
    name: "userCTest"
    email: "userCTest@gmail.com"
    password: "F7YTu_ER#$" 
    program: "01bbd541-939b-4b85-8d90-48ff0b02d0ee"
    restrictions: [
      "UmVzdHJpY3Rpb246M2ZmZDQ1OGUtMjczZi00MTZmLWE5NjYtNmFkYzliYjQ3OWE1",
      "UmVzdHJpY3Rpb246ODU1ZjkzZjYtODQzOC00MTIzLTk3YzktM2U2YzU2MzllZjli"
    ] 
  ) {
    success
    message
    user {
      id
      databaseId
      profileId
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```graphql
{
  "data": {
    "createUser": {
      "success": true,
      "message": "User created",
      "user": {
        "id": "VXNlcjpWWE5sY2pvNE5USmhNV1ZpTWkwek1EWm1MVFJsWlRFdE9HVmlaUzB4WlROa016WTNNV014TXpFPQ==",
        "databaseId": "852a1eb2-306f-4ee1-8ebe-1e3d3671c131",
        "profileId": "97e4dd59-46bc-4f50-89b4-cdacbf57f515"
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

### Send an email to set up a password

The following example creates a user and sends a password notification to the user's email to set up a password.

{% tabs %}
{% tab title="Mutation" %}

```php
mutation {
   createUser(
    name: "Liliana"
    email: "liliana@suggestic.com" emailPasswordNotification: true
  ) {
    success
    message
    user {
      id
      databaseId
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```php
{
  "data": {
    "createUser": {
      "success": true,
      "message": "User created",
      "user": {
        "id": "VXNlcjpWWE5sY2pwa05EYzFaR0ZpT0MwMFpESXpMVFJqTkRndFlXTTBNUzFsWkRJM1lqTXpZekZtWlRVPQ==",
        "databaseId": "d475dab8-4d23-4c48-ac41-ed27b33c1fe5"
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

The following notification will arrive in the user's email:

![](https://920729701-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LwqSnBDpAb6mFZYLsuB%2F-MbvIMzX2NFYOxUVLyOh%2F-Mc9hS3Oo3tZz5LCMtar%2Fimage.png?alt=media\&token=3eae440d-cfe3-4e5f-9a1c-2e3ee75a32b2)

Click on **this link** to set up the password, users are redirected to the following page where a new password must be introduced:

![](https://920729701-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LwqSnBDpAb6mFZYLsuB%2F-MbvIMzX2NFYOxUVLyOh%2F-Mc9hltHauXMaQ_AgPBk%2Fimage.png?alt=media\&token=06a9f314-e97b-4dcf-8138-098fa4bc6fb9)

### Assign a subscription to the user

{% tabs %}
{% tab title="Request" %}

```graphql
mutation {
  createUser(
    name: "userCTest"
    email: "userCTest@gmail.com"
    program: "01bbd541-939b-4b85-8d90-48ff0b02d0ee"
    subscription: "NjI2NzEwNDEtOTI5Yi00MzJlLWJhN2ItMDNjZjFmZWYzZGQ0"
  ) {
    success
    message
    user {
      id
      databaseId
      profileId
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```
{
  "data": {
    "createUser": {
      "success": true,
      "message": "User created",
      "user": {
        "id": "VXNlcjpWWE5sY2pvNE5USmhNV1ZpTWkwek1EWm1MVFJsWlRFdE9HVmlaUzB4WlROa016WTNNV014TXpFPQ==",
        "databaseId": "852a1eb2-306f-4ee1-8ebe-1e3d3671c131",
        "profileId": "97e4dd59-46bc-4f50-89b4-cdacbf57f515"
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

The following message is displayed in case the subscription does not exist:

{% tabs %}
{% tab title="Response" %}

```graphql
{
  "data": {
    "createUser": {
      "success": false,
      "message": "Subscription doesn't exist",
      "user": null
    }
  }
}
```

{% endtab %}
{% endtabs %}
