# PATCH - Update

The Custom Audience API 1.1 only accepts install IDs for the moment. For audiences with custom user IDs or advertising IDs, the version 1.0 should be used.

The Custom Audience API enables you to create, update, delete and list custom audiences. A **custom audience** can contain a list of custom user IDs, advertising IDs *(GAID or IDFA)* or install IDs.

This is useful to target segments with push notifications or In-App messages, either they are coming from your userbase or created by third-party tools.

Custom audiences created using the API can be targeted from Batch’s dashboard or the [Campaigns API](https://github.com/BatchLabs/product.tech-documentation-gitbook/blob/master/api/campaigns/create/README.md).

**NOTE**: Custom Audiences with install IDs are only supported from the 1.1 version of the Custom Audience API. Also note that this version doesn't support custom user IDs and advertising IDs for the moment.

### Request structure

#### Route

The Custom Audience API exposes a PATCH endpoint that allows to add or delete users from a custom audience :

`https://api.batch.com/1.1/BATCH_API_KEY/custom-audience/AUDIENCE_NAME`

Here is a valid cURL example:

```bash
curl -H "Content-Type: application/json" -H "X-Authorization: BATCH_REST_API_KEY" -X PATCH -d "@payload.json" "https://api.batch.com/1.1/BATCH_API_KEY/custom-audience/AUDIENCE_NAME"
```

The `AUDIENCE_NAME` value is the name of the existing audience you want this operation to be applied to.

The `BATCH_API_KEY` value is either your **Live**, **Dev** or **SDK** Batch API key from the settings page of your app within the dashboard (⚙ Settings → General).

#### Headers

In order to authenticate with the API, you need to provide your **company REST API Key** as the value of the `X-Authorization` header. You can find it in ⚙ Settings → General.

#### Patch data

The body of the request must contain a **valid JSON payload** describing the operations to be executed on the custom audience.

Here is a how a complete JSON payload looks like:

```json
{
  "ids": [
    {
      "action": "add",
      "id": "INSTALL-ID-1",
      "attributes": {
        "att1": 3,
        "att2": "string",
        "date(att15)": "2012-08-12T22:30:05",
        "url(att20)": "https://example.com/image.jpg"
      },
      "tags": ["value-1", "value-2"]
    },
    {
      "action": "remove",
      "id": "INSTALL-ID-2"
    }
  ]
}
```

Let's see the parameters in detail.

<table data-full-width="true"><thead><tr><th width="107.5">Id</th><th>Description</th></tr></thead><tbody><tr><td><code>ids</code></td><td><strong>Array of Objects</strong> - <em>Required</em><br>An array of objects describing actions to be applied to the custom audience.<br>Supports up to 10,000 elements.<br><em>E.g.</em><code>[{"action":"add","id":"USER_CUSTOM_ID1"}]</code></td></tr></tbody></table>

<table data-header-hidden><thead><tr><th width="140.5"></th><th width="529"></th></tr></thead><tbody><tr><td><code>action</code></td><td><strong>String</strong> - <em>Required</em><br>The action to be applied to the custom audience.<br>Acceptable values include: <code>add</code> or <code>remove</code> .<br><em>E.g.</em><code>{"action":"add"}</code></td></tr><tr><td><code>id</code></td><td><strong>String</strong> -<br>The ID that will be added to or deleted from the audience.<br><em>E.g.</em><code>{"id":"USER_CUSTOM_ID"}</code></td></tr><tr><td><code>attributes</code></td><td><strong>Object</strong> - <em>Optional. Only accepted for <code>add</code> action.</em><br>An object containing attributes to be attached to the id. They can then be used in <a href="https://doc.batch.com/guides/message-personalization/advanced/#custom-audience-data">message personalization.</a><br>Supports up to 15 elements. See the Custom Data API documentation for more info on attribute names and values.</td></tr><tr><td><code>tags</code></td><td><strong>Array</strong> - <em>Optional. Only accepted for <code>add</code> action.</em><br>An object containing tag values to be attached to the id. See the Trigger Events API documentation for more info on value limits.</td></tr></tbody></table>

**NOTE**: If multiple actions are given for the same ID, only the last one will be taken into account.

The [Custom Data API](/developer/api/mep/custom-data-api.md) documentation describes what the attribute name and value formats are, and which type to use depending on your use case. The main differences are that Custom Audiences attributes do **not** use the "u." prefix, and tag collections are not supported.

### Responses

#### Success

If the PATCH to the API endpoint is successful you will receive an **HTTP 201** confirmation and **a token**.

```json
{
  "indexing_token": "a0082dc6860938a26280bd3ba927303b"
}
```

Once you get your token, you can use it to [check the indexing state](/developer/api/mep/custom-audience/1.1/get.md) of this update with the API.

#### Failure

If the POST data does not meet the API requirements you will receive an actionable error message. Contact us at <support@batch.com> if you need further support.

* `AUTHENTICATION_INVALID` (Http status code: 401, Error code: 10)
* `API_MISUSE` (Http status code: 403, Error code: 12)
* `ROUTE_NOT_FOUND` (Http status code: 404, Error code: 20)
* `MISSING_PARAMETER` (Http status code: 400, Error code: 30)
* `MALFORMED_PARAMETER` (Http status code: 400, Error code: 31)
* `MALFORMED_JSON_BODY` (Http status code: 400, Error code: 32)
* `SERVER_ERROR` (Http status code: 500, Error code: 1)
* `MAINTENANCE_ERROR` (Http status code: 503, Error code: 2)

### Processing time

While the indexation of IDs is usually done in realtime, we offer no guarantees. If you send a campaign right after the custom audience creation, you might end up with a campaign targeting nobody.


---

# 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://doc.batch.com/developer/api/mep/custom-audience/1.1/update.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.
