• iOS
  • Android
  • Windows
  • Web
  • Cordova
  • Unity
  • Adobe Air
  • Dashboard
  • API
  • Guides
  • FAQ
  • API > Custom Audience API

    PATCH - Update

    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 or advertising IDs (GAID or IDFA).

    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.

    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.0/BATCH_API_KEY/custom-audience/AUDIENCE_NAME

    Here is a valid cURL example:

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

    The AUDIENCE_NAME value must be a string that only contains letters, numbers or the following characters : _, -.

    The BATCH_API_KEY value is either your Live or Dev 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.

    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:

    
    {
        "type": "custom_ids",
        "ids": [
            {
                "action": "add",
                "id": "USER_CUSTOM_ID1"
            },
            {
                "action": "remove",
                "id": "USER_CUSTOM_ID2"
            }
        ]
    }

    Let's see the parameters in detail.

    IdDescription
    typestring - Required
    Type of the audience.
    Acceptable values include: custom_ids or advertising_ids.
    E.g.{"type":"custom_ids"}
    idsArray of Objects - Required
    An array of objects describing actions to be applied to the custom audience.
    Supports up to 10,000 elements.
    E.g.[{"action":"add","id":"USER_CUSTOM_ID1"}]
    actionString - The action to be applied to the custom audience.
    Acceptable values include: add or remove.
    E.g.{"action":"add"}
    idString - The ID that will be added to or deleted from the audience.
    E.g.{"id":"USER_CUSTOM_ID"}

    NOTE: If both add and remove actions are applied to the same ID, the ID will be deleted from the audience.

    Responses

    Success

    If the POST to the API endpoint is successful you will receive an HTTP 200 confirmation and an empty json payload.

    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)
    • 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 garanties. If you send a campaign right after the custom audience creation, you might end up with a campaign targeting nobody.