> For the complete documentation index, see [llms.txt](https://cartsguru.gitbook.io/custom-integration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cartsguru.gitbook.io/custom-integration/data-apis/contacts/batch.md).

# Batch

This endpoint allows you to send a batch of actions for processing contacts.

## Batch

<mark style="color:green;">`POST`</mark> `https://api.carts.guru/contacts/v1/batch`

#### Headers

| Name          | Type   | Description                                    |
| ------------- | ------ | ---------------------------------------------- |
| authorization | string | <p>See Authorization page for example.<br></p> |

#### Request Body

| Name    | Type  | Description                                                                                                      |
| ------- | ----- | ---------------------------------------------------------------------------------------------------------------- |
| actions | array | An array of actions matching the sample objects below which contain either a delete, create, or update property. |

{% tabs %}
{% tab title="200 Batch successfully queued." %}

```
{    
  data: {
    batchId: "1234asdf1234"
  }
}
```

{% endtab %}

{% tab title="400 Your request failed validation" %}

```
{
  errors: [
    "siteId" is required, 
    "optoutEmail" must be a boolean
  ]
}
```

{% endtab %}

{% tab title="401 You failed authentication." %}

```
{
  errors: [
    status: 401, 
    message: 'UNAUTHORIZED'
  ]
}
```

{% endtab %}
{% endtabs %}

### Authorized Actions

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

```javascript
{
    "actions": [
        {
            "create": {
                // At least one of the three identifiers is REQUIRED 
                // email, phoneNumber, accountId
                email: String        // The contact's email
                phoneNumber: String  // The contact's phone number
                accountId: String    //The contact's accountId on your platform
                 
                firstname: Optional (String)     // The contact's first name
                lastname: Optional (String)      // The contact's last name
                optoutEmail: Optional (Boolean)  // true if they are opted out.
                optoutSms: Optional (Boolean)    // true if they are opted out.
                addresses: Optional (Array of Objects) - Addresses of the contact.
                ex: 
                    [
                        {
                            title
                            line1
                            line2
                            city
                            zipcode
                            country - Required if passing in addresses.
                        }
                    ] 
            }
        }
    ]
}
```

{% endtab %}

{% tab title="Delete" %}

```
{
    actions: [
        {
            delete: {
                // Only one of these three, will error if you provide more than one
                email: The contact's email 
                phoneNumber: The contact's phone number
                accountId: The contact's accountId on your platform
            }
        }
}
```

{% endtab %}

{% tab title="Update" %}
{% hint style="info" %}
At least one of the three identifiers is **required:**

* email
* phoneNumber
* accountId
  {% endhint %}

```javascript
{
  actions: [{
    update: {
      email: Identifying (String),       // The contact's email
      phoneNumber: Identifying (String), // The contact's phone number
      accountId: Identifying (String),   // The contact's accountId on your platform
      firstname: Optional (String),      // The contact's first name
      lastname: Optional (String),       // The contact's last name
      optoutEmail: Optional (Boolean),   // if they are opted out, false if they are opted in
      optoutSms: Optional (Boolean),     // if they are opted out, false if they are opted in
      addresses: [{                      // Addresses of the contact.
        // You can pass a list of addresses in
        // the following format
          title: Optional (String),     // The contact's first name
          line1: Optional (String),
          line2: Optional (String),
          city: Optional (String),
          zipcode :Optional (String),
          country: Require(String)
        }
      ]
    }
  }]
}
```

{% endtab %}
{% endtabs %}

### Code samples

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

```javascript
import fetch from 'node-fetch'

const res = await fetch(`https://api.carts.guru/contacts/v1/batch`, {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    authorization: 'Basic c8l0ZS0xOjE1ODQwMzc4MTI6Q2wwWHNoVHLaUFdHaDR0ZkZpVkdlbFlaMUxpeDdtdVR6SnBDUndHZlgydz0='
  },
  body: JSON.stringify({
    actions: [
      { delete: { email: 'hi@carts.guru' } },
      { delete: { phoneNumber: '41343432413' } },
      { delete: { accountId: 'accountId-1' } },
      {
        create: {
          phoneNumber: '14158888888',
          email: 'bobsburgers@carts.guru',
          firstname: 'bob',
          lastname: 'burger'
        }
      },
      {
        update: {
          accountId: '7777777',
          email: 'bern777@carts.guru',
          phoneNumber: '14157777777',
          firstname: 'Bern'
        }
      }
    ]
  })
})
```

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}
