# Users

## Register User

<mark style="color:green;">`POST`</mark> `https://api.codemash.io/:version/membership/users/register`

Register a new user to a particular project.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

#### Request Body

| Name        | Type    | Description                                                                                    |
| ----------- | ------- | ---------------------------------------------------------------------------------------------- |
| email       | string  | User's email address.                                                                          |
| password    | string  | User's password.                                                                               |
| displayName | string  | User's display name.                                                                           |
| firstName   | string  | User's first name.                                                                             |
| lastName    | string  | User's last name.                                                                              |
| roles       | array   | Roles to give to the newly created user (don't provide any to use default role from settings). |
| autoLogin   | boolean | Should the user be logged in after registering? The default is **true**.                       |
| meta        | string  | User's meta details as a JSON object.                                                          |

{% tabs %}
{% tab title="200 Returns user's authorization token and ID." %}

```javascript
{
    "result": true,
    "apiKey": "{AUTHORIZATION_KEY}",
    "userId": "{USER_ID_GUID}",
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

membershipService.RegisterUser(new RegisterUserRequest
{
    Email = "test@email.com",
    Password = "password123"
});
```

{% endtab %}

{% tab title="Node" %}

```csharp
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}

#### Membership Settings

There are some settings for user registration inside your dashboard under sections **Registration** and **Verification**.

* **User registers as** - if you don't provide roles during registration, the user will be given a selected role in the settings.
* **Verification by email needed** - if this is checked, the user will be unverified until verified through email. Email service needs to be enabled for this option. Also in your template, you have to set a token named **@Model.ValidationToken** which will be replaced by a verification token.
  {% endhint %}

## Invite User

<mark style="color:green;">`POST`</mark> `https://api.codemash.io/:version/membership/users/invite`

Invites an user to a particular project.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

#### Request Body

| Name        | Type   | Description                                                                                    |
| ----------- | ------ | ---------------------------------------------------------------------------------------------- |
| email       | string | User's email address.                                                                          |
| displayName | string | User's display name.                                                                           |
| firstName   | string | User's first name.                                                                             |
| lastName    | string | User's last name.                                                                              |
| roles       | array  | Roles to give to the newly created user (don't provide any to use default role from settings). |
| meta        | string | User's meta details as a JSON object.                                                          |

{% tabs %}
{% tab title="200 Returns user's ID." %}

```javascript
{
    "result": true,
    "userId": "{USER_ID_GUID}"
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

membershipService.InviteUserAsync(new InviteUserRequest
{
    Email = "test@email.com",
});
```

{% endtab %}

{% tab title="Node" %}

```csharp
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}

### Membership Settings

There are some settings for user invitation inside your dashboard under sections **Registration** and **Invitation**.

* **User registers as** - if you don't provide roles during registration, the user will be given a selected role.
* **Allow invite users** - this **MUST** be checked for invitations to work. Email service needs to be enabled for this option. Also in your template, you have to set a token named **@Model.ValidationToken** which will be replaced by an invitation token.
  {% endhint %}

## Get Users

<mark style="color:blue;">`GET`</mark> `https://api.codemash.io/:version/membership/users`

Gets a list of project users.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Query Parameters

| Name               | Type    | Description                           |
| ------------------ | ------- | ------------------------------------- |
| includePermissions | boolean | Includes permissions to the response. |
| includeDevices     | boolean | Includes devices to the response.     |
| includeMeta        | boolean | Includes meta to the response.        |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

{% tabs %}
{% tab title="200 Returns a list of users." %}

```javascript
{
    "totalCount": 20,
    "result": [
        {
            "id": "{USER_ID}",
            "email": "test@test.com"
            ...
        },
        ...
    ]
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var response = await membershipService.GetUsersListAsync(new GetUsersRequest());
```

{% endtab %}

{% tab title="Node" %}

{% endtab %}
{% endtabs %}

## Get User

<mark style="color:blue;">`GET`</mark> `https://api.codemash.io/:version/membership/users/:id`

Gets a project user.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |
| id      | string | User's ID.                     |

#### Query Parameters

| Name                       | Type    | Description                               |
| -------------------------- | ------- | ----------------------------------------- |
| IncludeUnreadNotifications | boolean | Includes unread push notifications count. |
| includePermissions         | boolean | Includes permissions to the response.     |
| includeDevices             | boolean | Includes devices to the response.         |
| includeMeta                | boolean | Includes meta to the response.            |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

{% tabs %}
{% tab title="200 Returns a list of users." %}

```javascript
{
    "totalCount": 20,
    "result": [
        {
            "id": "{USER_ID}",
            "email": "test@test.com"
            ...
        },
        ...
    ]
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var response = await membershipService.GetUserAsync(new GetUserRequest
{
    Id = Guid.Parse("{USER_ID}")
});
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}
{% endtabs %}

## Get User (By Email)

<mark style="color:blue;">`GET`</mark> `https://api.codemash.io/:version/membership/users/by-email`

Gets a project user by email.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Query Parameters

| Name                       | Type    | Description                               |
| -------------------------- | ------- | ----------------------------------------- |
| IncludeUnreadNotifications | boolean | Includes unread push notifications count. |
| includePermissions         | boolean | Includes permissions to the response.     |
| includeDevices             | boolean | Includes devices to the response.         |
| includeMeta                | boolean | Includes meta to the response.            |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

{% tabs %}
{% tab title="200 Returns a list of users." %}

```javascript
{
    "totalCount": 20,
    "result": [
        {
            "id": "{USER_ID}",
            "email": "test@test.com"
            ...
        },
        ...
    ]
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var response = await membershipService.GetUserAsync(new GetUserRequest
{
    Email = "john.doe@email.com"
});
```

{% endtab %}
{% endtabs %}

## Update profile

<mark style="color:purple;">`PATCH`</mark> `https://api.codemash.io/:version/membership/users/profile`

Updates the user's profile with given parameters. Only the provided values are updated. This request does not update user roles.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

#### Request Body

| Name                 | Type    | Description                                                                                                             |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| unsubscribedNewsTags | array   | Marketing email types to unsubscribe from. If value not provided then it's not updated. To delete, pass an empty array. |
| subscribeToNews      | boolean | Should a user receive marketing emails? If value not provided then it's not updated.                                    |
| timeZone             | string  | Default user's timezone.                                                                                                |
| language             | string  | Default user's language (mainly for notifications).                                                                     |
| displayName          | string  | User's display name.                                                                                                    |
| firstName            | string  | User's first name.                                                                                                      |
| lastName             | string  | User's last name.                                                                                                       |
| meta                 | string  | User's meta details as JSON.                                                                                            |

{% tabs %}
{% tab title="200 Returns true if updated." %}

```javascript
{
    "result": true
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var response = await membershipService.UpdateUserAsync(new UpdateUserRequest
{
    Id = Guid.Parse("{USER_ID}"),
    DisplayName = "Updated Name"
});
```

{% endtab %}
{% endtabs %}

## Update user

<mark style="color:purple;">`PATCH`</mark> `https://api.codemash.io/:version/membership/users/:id`

Updates user with given parameters. Only the provided values are updated. This request allows us to update user roles.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |
| id      | string | User's ID.                     |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

#### Request Body

| Name                 | Type    | Description                                                                                                             |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| unsubscribedNewsTags | array   | Marketing email types to unsubscribe from. If value not provided then it's not updated. To delete, pass an empty array. |
| subscribeToNews      | boolean | Should user receive marketing emails? If value not provided then it's not updated.                                      |
| timeZone             | string  | Default user's timezone.                                                                                                |
| language             | string  | Default user's language (mainly for notifications).                                                                     |
| displayName          | string  | User's display name.                                                                                                    |
| firstName            | string  | User's first name.                                                                                                      |
| lastName             | string  | User's last name.                                                                                                       |
| roles                | array   | Roles to set for a user.                                                                                                |
| meta                 | string  | User's meta details as JSON.                                                                                            |

{% tabs %}
{% tab title="200 Returns true if updated." %}

```javascript
{
    "result": true
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var response = await membershipService.UpdateUserAsync(new UpdateUserRequest
{
    Id = Guid.Parse("{USER_ID}"),
    DisplayName = "Updated Name"
});
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}
{% endtabs %}

## Delete user

<mark style="color:red;">`DELETE`</mark> `https://api.codemash.io/:version/membership/users/:id`

Deletes a project user.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |
| id      | string | User's ID.                     |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

{% tabs %}
{% tab title="200 Returns true if deleted." %}

```javascript
{
    "result": true
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var reponse = await membershipService.DeleteUserAsync(new DeleteUserRequest
{
    Id = Guid.Parse("{USER_ID}"),
});
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}
{% endtabs %}

## Block user

<mark style="color:purple;">`PATCH`</mark> `https://api.codemash.io/:version/membership/users/:id/block`

Blocks users from calling any authenticated requests.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |
| id      | string | User's ID.                     |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

{% tabs %}
{% tab title="200 Returns true if blocked." %}

```javascript
{
    "result": true
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var reponse = await membershipService.DeleteUserAsync(new DeleteUserRequest
{
    Id = Guid.Parse("{USER_ID}"),
});
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}
{% endtabs %}

## Unblock user

<mark style="color:purple;">`PATCH`</mark> `https://api.codemash.io/:version/membership/users/:id/unblock`

Unblocks user allowing to call authenticated calls.

#### Path Parameters

| Name    | Type   | Description                    |
| ------- | ------ | ------------------------------ |
| version | string | A version of the API endpoint. |
| id      | string | User's ID.                     |

#### Headers

| Name           | Type   | Description                                                                                            |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| Authorization  | string | Secret API key which belongs to your project or user. Not required if using cookies with a session ID. |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter.                                                 |

{% tabs %}
{% tab title="200 Returns true if unblocked." %}

```javascript
{
    "result": true
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var membershipService = new CodeMashMembershipService(client);

var reponse = await membershipService.UnblockUserAsync(new UnblockUserRequest
{
    Id = Guid.Parse("{USER_ID}"),
});
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.codemash.io/api/membership/users.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
