> For the complete documentation index, see [llms.txt](https://docs.venuzle.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.venuzle.com/manager-api/internal-endpoints/partner/users.md).

# Users

Endpoints to work with the users of a partner.

## Get users

<mark style="color:blue;">`GET`</mark> `/api/internal/v1/partners/:partner_id/users`

Get the users of the given partner. The users are paginated and can be optionally searched by giving the `search` query parameter.\
\
The action must be performed by an authenticated user with permission `users.read` and partner access.

#### Path Parameters

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| partner\_id | integer | The id of the partner. |

#### Query Parameters

| Name   | Type    | Description                                                                                          |
| ------ | ------- | ---------------------------------------------------------------------------------------------------- |
| page   | integer | The current page to display.                                                                         |
| search | string  | Filter users by the given string. It searches the users by first name, last name, and email address. |

{% tabs %}
{% tab title="200 The partner users are returned." %}

```
{
    data: [
        {
            id: 1,
            first_name: "John",
            last_name: "Doe",
            email: "john.doe@example.com"
        },
        {
            id: 2,
            first_name: "Jane",
            last_name: "Doe",
            email: "jane.doe@example.com"
        }
    ],

    meta: {
        current_page: 1,
        from: 1,
        to: 2,
        per_page: 20,
        total: 2,
    },
    
    links: {
        first: "https://manager.apis.venuzle.com/api/internal/v1/partners/1/users?search=Doe&page=1",
        last: "https://manager.apis.venuzle.com/api/internal/v1/partners/1/users?search=Doe&page=1",
        prev: null,
        next: null
    }
}
```

{% endtab %}

{% tab title="401 The user is not authenticated." %}

```
{}
```

{% endtab %}

{% tab title="403 The user performing the has no access to the partner or the permission users.read is missing." %}

```
{}
```

{% endtab %}

{% tab title="404 The partner could not be found." %}

```
{}
```

{% endtab %}
{% endtabs %}

## Create a new user

<mark style="color:green;">`POST`</mark> `/api/internal/v1/partners/:partner_id/users`

Create a new user and attach it to the partner. \
\
If a user already exists with that email and is not attached to the given partner, it will be attached and the first\_name and last\_name differences will be ignored.\
\
The action must be performed by an authenticated user with permission `users.create` and partner access.<br>

#### Path Parameters

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| partner\_id | integer | The id of the partner. |

#### Request Body

| Name        | Type   | Description                        |
| ----------- | ------ | ---------------------------------- |
| password    | string | The password of the new user.      |
| email       | string | The email address of the new user. |
| last\_name  | string | The last name of the new user.     |
| first\_name | string | The first name of the new user.    |

{% tabs %}
{% tab title="201 The user was created and attached to the partner." %}

```
{
    data: {
        id: 1,
        first_name: "John",
        last_name: "Doe",
        email: "john.doe@example.com"
    }
}
```

{% endtab %}

{% tab title="401 The request was made without having an authenticated user." %}

```
{}
```

{% endtab %}

{% tab title="403 The user performing the action has no partner access or the permission users.create is missing." %}

```
{}
```

{% endtab %}

{% tab title="404 The partner could not be found." %}

```
{}
```

{% endtab %}

{% tab title="422 The data didn't pass the validation." %}

```
{
    message: "The given data was invalid.",
    errors: {
        first_name: [
            "The first_name field is required.",
            "The first_name field must be a string."
        ],
        
        last_name: [
            "The last_name field is required."
        ],
        
        email: [
            "The email field is required."
        ],
        
        password: [
            "The password field is required."
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Get user

<mark style="color:blue;">`GET`</mark> `/api/internal/v1/partners/:partner_id/users/:user_id`

Get a user by its id.\
\
The action must be performed by an authenticated user with permission `users.read` and partner access.

#### Path Parameters

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| user\_id    | integer | The id of the user.    |
| partner\_id | integer | The id of the partner. |

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

```
{
    data: {
        id: 1,
        first_name: "John",
        last_name: "Doe",
        email: "john.doe@example.com"
    }
}
```

{% endtab %}

{% tab title="401 The request was made without having an authenticated user." %}

```
{}
```

{% endtab %}

{% tab title="403 The user performing the action has no partner access or the permission users.read is missing." %}

```
{}
```

{% endtab %}

{% tab title="404 The partner or the user could not be found." %}

```
{}
```

{% endtab %}
{% endtabs %}

## Update user

<mark style="color:orange;">`PUT`</mark> `/api/internal/v1/partners/:partner_id/users/:user_id`

Update the given user.\
\
The action must be performed by an authenticated user with permission `users.update` and partner access.

#### Path Parameters

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| user\_id    | integer | The id of the user.    |
| partner\_id | integer | The id of the partner. |

#### Request Body

| Name                        | Type   | Description                            |
| --------------------------- | ------ | -------------------------------------- |
| new\_password\_confirmation | string | Confirmation of the new user password. |
| new\_password               | string | The new password of the user.          |
| email                       | string | The email of the user.                 |
| last\_name                  | string | The last name of the user.             |
| first\_name                 | string | The first name of the user.            |

{% tabs %}
{% tab title="204 The user was successfully updated." %}

```
{}
```

{% endtab %}

{% tab title="401 The request was made without an authenticated user." %}

```
{}
```

{% endtab %}

{% tab title="403 The user performing the request has no partner access or the permission users.update is missing." %}

```
{}
```

{% endtab %}

{% tab title="404 The partner or the user could not be found." %}

```
{}
```

{% endtab %}

{% tab title="422 The data didn't pass the validation." %}

```
{
    message: "The given data was invalid.",
    errors: {
        first_name: [
            "The first_name must be betweet 2 and 70 characters long."
        ],
        
        last_name: [
            "The last_name must be betweet 2 and 70 characters long."
        ],
        
        email: [
            "The email must be a valid email address."
        ],
        
        password: [
            "The password must be betweet 6 and 255 characters long."
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Delete user

<mark style="color:red;">`DELETE`</mark> `/api/internal/v1/partners/:partner_id/users/:user_id`

Delete the given user. \
\
If the user is attached to multiple partners, it will be removed from the current partner only.\
\
The action must be performed by an authenticated user with permission `users.delete` and partner access.

#### Path Parameters

| Name        | Type    | Description                          |
| ----------- | ------- | ------------------------------------ |
| user\_id    | integer | The user id which should be deleted. |
| partner\_id | integer | The partner id.                      |

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

```
{}
```

{% endtab %}

{% tab title="401 The request was made without an authenticated user." %}

```
{}
```

{% endtab %}

{% tab title="403 The user performing the request has no partner access or the permission users.delete is missing." %}

```
{}
```

{% endtab %}

{% tab title="404 The partner or the user could not be found." %}

```
{}
```

{% endtab %}

{% tab title="409 Returned when the user tries to delete its own account." %}

```
{}
```

{% endtab %}
{% endtabs %}

## Get user partners

<mark style="color:blue;">`GET`</mark> `/api/internal/v1/partners/:partner_id/users/:user_id`

Get the partners associated with the given user.

#### Path Parameters

| Name        | Type    | Description |
| ----------- | ------- | ----------- |
| user\_id    | integer |             |
| partner\_id | integer |             |

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

```
```

{% endtab %}
{% endtabs %}
