# Create User

## Create User

<mark style="color:green;">`POST`</mark> `https://{server_address}/api/v1/organization/users/create`

This endpoint will first create new organization under "Clients organizations" and then create a new user as a member of previously created organization.

#### Headers

| Name                                            | Type                   | Description |
| ----------------------------------------------- | ---------------------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | Bearer {access\_token} |             |
| Content-Type<mark style="color:red;">\*</mark>  | application/json       |             |

#### Request Body

| Name                                           | Type                                         | Description                                                                                                                            |
| ---------------------------------------------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| email<mark style="color:red;">\*</mark>        | <john@example.com>                           | New user's email                                                                                                                       |
| passwordHash<mark style="color:red;">\*</mark> | tk++TTJLCEKfWuhQyGAKCSRMop6wyIexGKylaknsUo8= | New user's password. See [user password creation notes](#user-password).                                                               |
| name<mark style="color:red;">\*</mark>         | John Doe                                     | New user's name. May contain up to 50 symbols. Only letters, hyphens, spaces, dots and apostrophes are allowed.                        |
| title                                          | String                                       | New user's title. May contain up to 50 symbols. Only letters, hyphens and spaces are allowed.                                          |
| nickName                                       | String                                       | New user's nickname. May contain up to 50 symbols. Only letters, digits, hyphens and spaces are allowed.                               |
| phoneNumber                                    | +3801234567                                  | New user's phone number. Should be prefixed with `+`.                                                                                  |
| organizationName                               | My Organization                              | New user's organization name. Should be from 3 to 100 symbols. Only letters, digits, dots, apostrophe, hyphens and spaces are allowed. |
| timeZone                                       | Europe/Kiev                                  | New user's timezone.                                                                                                                   |
| address                                        | String                                       | New user's address.                                                                                                                    |
| address.fullAddress                            | String                                       | New user's full address. Should be up to 512 symbols.                                                                                  |
| address.city                                   | String                                       | New user's city. Should be up to 50 symbols.                                                                                           |
| address.country                                | String                                       | New user's country. Should be up to 74 symbols.                                                                                        |
| address.state                                  | String                                       | New user's state. Should be up to 40 symbols.                                                                                          |
| address.zip                                    | String                                       | New user's zip code. Should be up to 12 symbols.                                                                                       |

{% tabs %}
{% tab title="204: No Content User created or already exists" %}

{% endtab %}
{% endtabs %}

Request examples:

<pre class="language-bash"><code class="lang-bash"># curl command example:
$ curl -X POST -H "Content-Type: application/json" \
<strong>      -H "Authorization: Bearer {accessToken}" \
</strong>      -d '{"email":"test@example.com","passwordHash":"tk++TTJLCEKfWuhQyGAKCSRMop6wyIexGKylaknsUo8=","name":"Test user","address":{"city":"Kyiv","country":"Ukraine"}}' \
      https://fra1.blynk.cloud/api/v1/organization/users/create

$ curl -X POST -H "Content-Type: application/json" \
      -H "Authorization: Bearer eIdWHQqRfFmvP5LDDh-IGxPUzi7I27HthzCPAVmS" \
      -d '{"email":"test@example.com","passwordHash":"tk++TTJLCEKfWuhQyGAKCSRMop6wyIexGKylaknsUo8=","name":"Test user","address":{"city":"Kyiv","country":"Ukraine"}}' \
      https://fra1.blynk.cloud/api/v1/organization/users/create
</code></pre>

### User password

Blynk using SHA-256 algorithm to encrypt user's password. Blynk never accept plain password on server-side, so to specify user's password you have to correctly encrypt it on your side.

Use lowercased user's email as a salt and encode this password using Base64 algorithm before passing it to Blynk.

Here is example Java code to encode user's password:

```java
String userEmail = "john@example.com";
String userPassword = "mySuperSecretPassword";

byte[] salt = MessageDigest.getInstance("SHA-256")
        .digest(userEmail.toLowerCase().getBytes(StandardCharsets.UTF_8));

MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(userPassword.getBytes(StandardCharsets.UTF_8));        
byte[] byteData = md.digest(salt);
String sha256Password = Base64.getEncoder().encodeToString(byteData);
// Pass 'sha256Password' to Blynk
```
