Update

See create to see an introduction about Audience API.

API Description

Update

post

Add or delete users from an audience.

Authorizations
AuthorizationstringRequired

API Key Authentication

Authentication is required in order to interact with Batch's APIs.

Batch implements authentication using API Keys, that we call the "REST API Key". You can find it on your dashboard.

Please make sure that you keep this key secret. You should never use it in client apps to call APIs from there as it would easily be extractable.

How to authenticate

In order to authenticate your requests, add your REST API Key in the Authorization header and prefix it by Bearer. Example: Authorization: Bearer bcd38d9rfb38ra28.

Header parameters
X-Batch-ProjectstringRequired

The unique project key, identifying a project on the Batch platform

Example: project_0664hxvwffvbpn278gxdyhsadddqgna6
Body
namestringRequired

The name of the existing audience you want this operation to be applied to.

Responses
post
/audiences/update
POST /2.8/audiences/update HTTP/1.1
Host: api.batch.com
Authorization: Bearer YOUR_SECRET_TOKEN
X-Batch-Project: text
Content-Type: application/json
Accept: */*
Content-Length: 229

{
  "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": "remove",
      "id": "CUSTOM-ID-2"
    }
  ]
}
{
  "indexing_token": "text"
}

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.

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:

{
  "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.

{
  "indexing_token": "a0082dc6860938a26280bd3ba927303b"
}

Once you get your token, you can use it to check the indexing state 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).

Last updated