> For the complete documentation index, see [llms.txt](https://academy.synap.ac/organisation-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://academy.synap.ac/organisation-api/api-reference/user.md).

# /user

## User

<mark style="color:green;">`POST`</mark> `https://api-org.synap.ac/users`

Register a new user to your organisation.

#### Headers

| Name             | Type   | Description                                                   |
| ---------------- | ------ | ------------------------------------------------------------- |
| x-api-key        | string | Your API usage token                                          |
| x-syn-org-id     | string | Your organisation's identifier on Synap                       |
| x-syn-org-secret | string | You organisation's secret key, used to authorise each request |
| content-type     | string | application/json                                              |

{% tabs %}
{% tab title="200 The user was successfully created." %}

```typescript
{
  "user": {
  "objectId": "A123TESTX9",
  "email": "test@email.com",
  "password": "Password123",
  "name": "Tom Smith",
  "attr": {
    "foo": true,
    "bar": 123
    }
  }
  "timestamp": "2020-03-30T10:05:16.754Z"
}
```

{% endtab %}

{% tab title="400 Various examples of bad requests" %}

```
// Email already exists in our database
{
  "code": 400,
  "error": "Account already exists for this username.";
}

// insufficient password security
{
  "code": 400,
  "error": "Password does not meet the password policy requirements.";
}
```

{% endtab %}
{% endtabs %}

#### Body Parameters

**User**

| Attribute | Type   | Required | Description                                                            |
| --------- | ------ | -------- | ---------------------------------------------------------------------- |
| email     | string | yes      | The user's email address                                               |
| password  | string | yes      | At least 8 characters, mixture of 1 uppercase, 1 lowercase and 1 digit |
| name      | string | yes      | The user's name                                                        |
| attr      | object | optional | Custom attributes you wish to set for the user                         |

**Actions**

| Attribute      | Type   | Required | Description                                                     |
| -------------- | ------ | -------- | --------------------------------------------------------------- |
| addToUserGroup | object | optional | Provide the id of the usergroup the new user should be added to |

#### Examples

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

```typescript
curl --request POST \
  --url https://api-org.synap.ac/users \
  --header 'content-type: application/json' \
  --header 'x-syn-org-id: org123test' \
  --header 'x-syn-org-secret: secret123test' \
  --header 'x-api-key: test123api' \
  --data '{
  "user": {
    "email": "test@email.com",
    "password": "Password123",
    "name": "Tom Smith",
    "attr": {
      "foo": true,
      "bar": 123
    }
  },
  "actions": {
    "addToUserGroup": "U6CoTESTL7"
  } 
}'
```

{% endtab %}

{% tab title="Request Body" %}

```typescript
{
  "user": {
    "email": "test@email.com",
    "password": "Password123",
    "name": "Tom Smith",
    "attr": {
      "foo": true,
      "bar": 123
    } 
  },
  "actions": {
    "addToUserGroup": "U6CoTESTL7"
  } 
}
```

{% endtab %}

{% tab title="Response" %}

```typescript
{
  "objectId": "A123TESTX9",
  "email": "test@email.com",
  "password": "Password123",
  "name": "Tom Smith",
  "attr": {
    "foo": true,
    "bar": 123
  }
  "timestamp": "2020-03-30T10:05:16.754Z"
}

--

403 Forbidden
{
  "code": 403,
  "error": "Unauthorised request."
}


```

{% endtab %}
{% endtabs %}

## Delete user

<mark style="color:red;">`DELETE`</mark> `{API_URL}/users/:objectId`

Permanently remove the user and all their data from your organisation.

#### Query Parameters

| Name     | Type   | Description              |
| -------- | ------ | ------------------------ |
| objectId | string | The user's **objectId**. |

#### Headers

| Name             | Type   | Description                                                     |
| ---------------- | ------ | --------------------------------------------------------------- |
| X-Api-Key        | string | Your API usage token                                            |
| X-Syn-Org-Id     | string | Your organisation's identifier on Synap                         |
| X-Syn-Org-Secret | string | Your organisation's secret key, used to authorised each request |
| Content-Type     | string | application/json                                                |

{% tabs %}
{% tab title="200 The user was deleted successfully." %}

```typescript
{
  "objectId": "A123TESTX9",
  "createdAt": "2020-03-27T12:00:00.000Z",
  "updatedAt": "2020-03-27T12:00:00.000Z",
  "email": "test@email.com",
  "name": "Tom Smith",
  "attr": {
    "foo": true,
    "bar": 123
  }
  "timestamp": "2020-03-30T10:05:16.754Z"
}
```

{% endtab %}

{% tab title="404 The user does not exist." %}

```
{
  "code": 404,
  "error": "Object not found.";
}
```

{% endtab %}
{% endtabs %}

#### Examples

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

```typescript
curl --request DELETE \
  --url https://api-org.synap.ac/users/A123TESTX9 \
  --header 'x-syn-org-id: org123test' \
  --header 'x-syn-org-secret: secret123test' \
  --header 'x-api-key: test123api' \
```

{% endtab %}

{% tab title="Response" %}

```typescript
200 Ok
{
  "objectId": "A123TESTX9",
  "createdAt": "2020-03-27T12:00:00.000Z",
  "updatedAt": "2020-03-27T12:00:00.000Z",
  "email": "test@email.com",
  "name": "Tom Smith",
  "attr": {
    "foo": true,
    "bar": 123
  }
  "timestamp": "2020-03-30T10:05:16.754Z"
}

--

403 Forbidden
{
  "code": 403,
  "error": "Unauthorised request."
}

--

404 Not Found
{ 
  "code": 404, 
  "error": "Object not found."
}
```

{% endtab %}
{% endtabs %}
