# Clients

Definitions of the types and format of the data used in the endpoints can be found at the bottom of the page.

## Endpoints

## Get Clients

<mark style="color:blue;">`GET`</mark> `https://cubicl.io/api/v1/crm/customers`

Gets clients matching the search criteria.

#### Query Parameters

| Name             | Type   | Description                                                                                                                                                                                                  |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name             | string | <p>Text to be searched in client name.</p><p>A match will occur only if a word in the client name <strong>starts with</strong> the given search text.</p><p>Search is <strong>case insensitive</strong>.</p> |
| email            | string | <p>Text to be searched in client or contact mail addresses.</p><p>Search is <strong>case insensitive.</strong></p>                                                                                           |
| includeAllFields | string | <p><code>true</code> to get all client fields.</p><p><code>false</code> to get only <code>name</code>.</p><p>Default is <code>false</code>.</p>                                                              |
| skip             | number | Default is 0.                                                                                                                                                                                                |
| limit            | number | Default is 10.                                                                                                                                                                                               |

{% tabs %}
{% tab title="200: OK List of clients" %}

```javascript
Client[]
```

{% endtab %}
{% endtabs %}

## Get Client By Id

<mark style="color:blue;">`GET`</mark> `https://cubicl.io/api/v1/crm/customers/:id`

**Path Parameters**

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | string | Client ID   |

{% tabs %}
{% tab title="200: OK Client details" %}

```javascript
Client
```

{% endtab %}

{% tab title="403: Forbidden You don't have the permission to view clients." %}

```javascript
{ code: 4 }
```

{% endtab %}
{% endtabs %}

## Create Client

<mark style="color:green;">`POST`</mark> `https://cubicl.io/api/v1/crm/customers`

Check the Client type definition below for field descriptions.

#### Request Body

| Name                                   | Type       | Description |
| -------------------------------------- | ---------- | ----------- |
| name<mark style="color:red;">\*</mark> | string     |             |
| fullname                               | string     |             |
| email                                  | string     |             |
| phone                                  | string     |             |
| contacts                               | Contact\[] |             |
| customFields                           | object     |             |
| portalCustomerManagerIds               | string\[]  |             |

{% tabs %}
{% tab title="200: OK Client details" %}

```javascript
Client
```

{% endtab %}
{% endtabs %}

## Update Client

<mark style="color:orange;">`PUT`</mark> `https://cubicl.io/api/v1/crm/customers/:id`

Check the Client type definition below for field descriptions.

#### Request Body

| Name                                   | Type       | Description |
| -------------------------------------- | ---------- | ----------- |
| name<mark style="color:red;">\*</mark> | string     |             |
| fullname                               | string     |             |
| email                                  | string     |             |
| phone                                  | string     |             |
| contacts                               | Contact\[] |             |
| customFields                           | object     |             |
| portalCustomerManagerIds               | string\[]  |             |

{% tabs %}
{% tab title="200: OK Client details" %}

```javascript
Client
```

{% endtab %}
{% endtabs %}

## Delete Client

<mark style="color:red;">`DELETE`</mark> `https://cubicl.io/api/v1/crm/customers/:id`

{% tabs %}
{% tab title="200: OK No content" %}

{% endtab %}
{% endtabs %}

## Data

#### Clients

```typescript
type Client = {
    _id: string;
    name: string; // A short name shown in UI and used for search
    phone: string;
    email: string;
    fullname: string;
    // People working at this client you are in contact with
    contacts: Contact[];
    // An object where keys are custom field ids and values are field values
    // customFields can be null
    customFields: {
        [fieldId: string]: string | null
    } | null;
    // List of user ids who get notifications for activities from portal users
    // of this client
    portalCustomerManagerIds: string[];
    createdAt: number;
}
```

#### Contacts

```typescript
type Contact = {
    name: string;
    position: string;
    phone: string;
    email: string;
}
```
