# Clients

API for managing Clients (Sub-User Accounts)

## List Clients

<mark style="color:blue;">`GET`</mark> `https://www.magloft.com/api/portal/v1/clients/`

This endpoint **returns** a list of `clients`

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

```javascript
{
  "total": 1,
  "page": 1,
  "records": [
    {
      "id": 1234,
      "firstname": "Amelia",
      "lastname": "Earhart",
      "email": "user@magloft.com",
      "created_at": "2018-01-24 10:55:35",
      "updated_at": "2018-01-24 10:55:35",
      "last_seen_at": "2018-01-24 10:55:35",
      "sign_in_count": 6,
      "gravatar_url": "//secure.gravatar.com/avatar/123456789987654321",
      "roles": [
        {
          "id": 1234,
          "user_id": 1211,
          "publication_id": 123,
          "access_level": "author",
          "created_at": "2018-01-24 10:55:35",
          "updated_at": "2018-01-24 10:55:35"
        }
      ]
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## Retrieve paginated list of clients

<mark style="color:blue;">`GET`</mark> `https://www.magloft.com/api/portal/v1/clients/page/:page`

This endpoint **returns** a page list of all `clients`

#### Path Parameters

| Name | Type    | Description             |
| ---- | ------- | ----------------------- |
| page | Integer | The page number to list |

#### Query Parameters

| Name            | Type    | Description                              |
| --------------- | ------- | ---------------------------------------- |
| per\_page       | Integer | Number of items to show per page         |
| order\_by       | Symbol  | Field to sort results by                 |
| order\_dir      | Symbol  | Direction (asc, desc) to sort results by |
| filter          | String  | Text filter to search results by         |
| publication\_id | Integer | Filter by publications ID                |

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

```javascript
{
  "total": 1,
  "page": 1,
  "records": [
    {
      "id": 1234,
      "firstname": "Amelia",
      "lastname": "Earhart",
      "email": "user@magloft.com",
      "created_at": "2018-01-24 10:55:35",
      "updated_at": "2018-01-24 10:55:35",
      "last_seen_at": "2018-01-24 10:55:35",
      "sign_in_count": 6,
      "gravatar_url": "//secure.gravatar.com/avatar/123456789987654321",
      "roles": [
        {
          "id": 1234,
          "user_id": 1211,
          "publication_id": 123,
          "access_level": "author",
          "created_at": "2018-01-24 10:55:35",
          "updated_at": "2018-01-24 10:55:35"
        }
      ]
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## GET Client

<mark style="color:blue;">`GET`</mark> `https://www.magloft.com/api/portal/v1/clients/:id`

This endpoint **returns** a specific `client` by `id`

#### Path Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | Integer | Client ID   |

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

```javascript
{
  "id": 1234,
  "firstname": "Amelia",
  "lastname": "Earhart",
  "email": "user@magloft.com",
  "created_at": "2018-01-24 10:55:35",
  "updated_at": "2018-01-24 10:55:35",
  "last_seen_at": "2018-01-24 10:55:35",
  "sign_in_count": 6,
  "gravatar_url": "//secure.gravatar.com/avatar/123456789987654321",
  "roles": [
    {
      "id": 1234,
      "user_id": 1211,
      "publication_id": 123,
      "access_level": "author",
      "created_at": "2018-01-24 10:55:35",
      "updated_at": "2018-01-24 10:55:35"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## Create new client

<mark style="color:green;">`POST`</mark> `https://www.magloft.com/api/portal/v1/clients/`

This endpoint **creates** a new `client` and **returns** the saved `client`

#### Request Body

| Name      | Type   | Description          |
| --------- | ------ | -------------------- |
| email     | String | Client email address |
| firstname | String | Client Firstname     |
| lastname  | String | Client Lastname      |
| password  | String | Client Password      |

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

```javascript
{
  "id": 1234,
  "firstname": "Amelia",
  "lastname": "Earhart",
  "email": "user@magloft.com",
  "created_at": "2018-01-24 10:55:35",
  "updated_at": "2018-01-24 10:55:35",
  "last_seen_at": "2018-01-24 10:55:35",
  "sign_in_count": 6,
  "gravatar_url": "//secure.gravatar.com/avatar/123456789987654321",
  "roles": [
    {
      "id": 1234,
      "user_id": 1211,
      "publication_id": 123,
      "access_level": "author",
      "created_at": "2018-01-24 10:55:35",
      "updated_at": "2018-01-24 10:55:35"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## Update Client

<mark style="color:orange;">`PUT`</mark> `https://www.magloft.com/api/portal/v1/clients/:id`

This endpoint **updates** a specific `client` by `id` and **returns** the updated `client`

#### Path Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | Integer | Client ID   |

#### Request Body

| Name                   | Type   | Description                  |
| ---------------------- | ------ | ---------------------------- |
| firstname              | String | Client Firstname             |
| lastname               | String | Client Lastname              |
| password               | String | Client Password              |
| password\_confirmation | String | Client Password Confirmation |

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

```javascript
null
```

{% endtab %}
{% endtabs %}

## Delete Client

<mark style="color:red;">`DELETE`</mark> `https://www.magloft.com/api/portal/v1/clients/:id`

This endpoint **deletes** a specific `client` by `id` and **returns** an `empty response` with status `204`

#### Path Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | Integer | Client ID   |

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

```javascript
null
```

{% endtab %}
{% endtabs %}

## Become Client

<mark style="color:blue;">`GET`</mark> `https://www.magloft.com/api/portal/v1/clients/:id/become`

This endpoint **logs in** as a `client` by `id` and **returns** the new `client` user

#### Path Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | Integer | Client ID   |

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

```javascript
null
```

{% endtab %}
{% endtabs %}
