# Update

See [create](/developer/api/cep/audiences/create.md) to see an introduction about Audience API.

### API Description

## Update

> Add or delete users from an audience.

```json
{"openapi":"3.1.0","info":{"title":"Batch - REST API","version":"2.9"},"tags":[{"name":"Audiences"}],"servers":[{"url":"https://api.batch.com/{version}","description":"production","variables":{"version":{"default":"2.11","description":"Version of the API"}}}],"security":[{"rest_key":[]}],"components":{"securitySchemes":{"rest_key":{"type":"http","scheme":"bearer","description":"## API Key Authentication\n\nAuthentication is required in order to interact with Batch's APIs.\n\nBatch implements authentication using API Keys, that we call the \"REST API Key\".\nYou can find it on your dashboard.\n\nPlease make sure that you keep this key secret. You should never use it in client apps to call APIs from there as it would\neasily be extractable.\n\n### How to authenticate\n\nIn order to authenticate your requests, add your REST API Key in the `Authorization` header and prefix it by `Bearer`. Example: `Authorization: Bearer bcd38d9rfb38ra28`.\n"}},"parameters":{"HeaderProjectKey":{"in":"header","name":"X-Batch-Project","description":"The unique project key, identifying a project on the Batch platform","schema":{"type":"string"},"required":true}},"responses":{"400":{"description":"The request is malformed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"The Rest API Key is not valid for this project","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Too Many Requests","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Batch's services are under maintenance. Please try again later","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"asyncResponse":{"description":"If the POST to the API endpoint is successful you will receive an HTTP 202 confirmation and an indexing token. <br/>Once you get your indexing token, you can use it to check the indexing state with the view action.\n","content":{"application/json":{"schema":{"type":"object","properties":{"indexing_token":{"type":"string"}}}}}}},"schemas":{"Error":{"type":"object","required":["error_message","error_code"],"properties":{"error_message":{"description":"A human readable error message","type":"string"},"error_code":{"description":"Error code","type":"string"}}}}},"paths":{"/audiences/update":{"post":{"operationId":"audience_update","summary":"Update","description":"Add or delete users from an audience.","tags":["Audiences"],"parameters":[{"$ref":"#/components/parameters/HeaderProjectKey"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name","ids"],"properties":{"name":{"type":"string","description":"The name of the existing audience you want this operation to be applied to."},"ids":{"type":"array","maxItems":10000,"description":"An array of objects describing actions to be applied to the audience. <br/>If multiple actions are given for the same ID, only the last one will be taken into account.\n","items":{"type":"object","required":["action","id"],"properties":{"action":{"type":"string","enum":["add","remove"],"description":"The action to be applied to the audience."},"id":{"type":"string","description":"The ID that will be added to or deleted from the audience."},"attributes":{"type":"object","description":"Only accepted for `add` action. <br/>An object containing attributes to be attached to the id. They can then be used in [message personalization](https://doc.batch.com/guides/message-personalization/advanced/#custom-audience-data). <br/>Supports up to 15 elements. See the Custom Data API documentation for more info on attribute names and values.\n"}}}}}}}}},"responses":{"202":{"$ref":"#/components/responses/asyncResponse"},"400":{"$ref":"#/components/responses/400"},"401":{"$ref":"#/components/responses/401"},"429":{"$ref":"#/components/responses/429"},"500":{"$ref":"#/components/responses/500"},"503":{"$ref":"#/components/responses/503"}}}}}}
```

### Request structure

#### Route

The Audience API exposes a POST endpoint that allows to add or delete users from an audience:

`/audiences/update`

#### Headers and authentication

See [Overview → Using Project APIs](/developer/api/cep.md#request-headers-and-authentication).

#### Post data

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

Here is a how a complete JSON payload looks like:

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

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

### Responses

#### Success

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

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

Once you get your token, you can use it to [check the indexing state](/developer/api/cep/audiences/view.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.

### Processing time

While the indexation of IDs is usually done in real time, we offer no guarantees. If you send a campaign right after the audience creation, you might end up with a campaign targeting nobody. A call to the view action with the indexing token replies with an APPLIED indexing state if the processing is finished (and IN\_PROCESS if it is still ongoing).


---

# 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/cep/audiences/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.
