- Read endpoints require the
context-targeting:readscope, and write endpoints requirecontext-targeting:write. See Prerequisites. - Your API key determines the project, so paths don’t include a project ID.
- Each endpoint lists only its own errors. For errors that apply to all endpoints, see Error Codes.
Targeting Object
The list, get, create, and rename endpoints return targetings in the following format. Delete endpoints return only_id. In API fields, options are called categories.
categories and syncedAt aren’t included in every response:
syncedAt is omitted until the targeting’s first load finishes. After you change Context IDs, add an option, or move or detach an option, it’s usually omitted until the next load finishes.
To check whether a change has been loaded, compare the time the change succeeded with
syncedAt. Don’t rely on whether syncedAt is present. See When Changes Take Effect.List Targetings
Returns all context targetings in your project. Audience targetings aren’t included, and the list isn’t paginated.Request
context-targeting:read scope.
Query Parameters
Example Request
Example Response
200 with an array of targeting objects:
Get a Targeting
Returns one context targeting.Request
context-targeting:read scope.
Path Parameters
Query Parameters
Example Request
Example Response
200 with a targeting object:
Create a Targeting
Creates a context targeting. You can create its options in the same request.Request
context-targeting:write scope.
Request Body
Each item in
categories takes the following fields:
- A request can include up to 10,000 Context IDs in total, including those of sub-options.
- The server generates all IDs. A request that includes
_idfails with400. - Items in
categoriescan’t includeparent. A request that includes it fails with400. To add an option to an existing option group, see Add an Option to an option group. - To create more than 100 options, create the targeting first, and then use Add Options in Bulk.
Example Request
Example Response
201 with the new targeting object, including its options:
_id of the targeting and of each option. You need them to change the targeting later.
Errors
If the name is already in use, the response looks like this:
Rename a Targeting
Changes the name of a targeting. Its options and Context IDs don’t change.Request
context-targeting:write scope.
Path Parameters
Request Body
Example Request
Example Response
200 with the renamed targeting object, without categories. To read its options, use Get a Targeting or List Options.
Delete a Targeting
Deletes a targeting and all of its options, including option groups and sub-options.Request
context-targeting:write scope.
Path Parameters
Example Request
Example Response
200 with only the ID of the deleted targeting:
Bulk Operations
Create, rename, or delete up to 100 targetings in one request.- The request is checked as a whole first: the number of items (1–100), the format of each field, and the totals per request. If the check fails, the whole request fails with
400, and nothing is applied. - If another API write for your project is in progress, the whole request can fail with
409 CONTEXT_TARGETING_WRITE_IN_PROGRESS, and nothing is applied. See Concurrent Writes. - Otherwise, the response is
200with a result for each item, even if every item fails. Some items can succeed while others fail, so checksuccessfor each item.
Create and delete requests apply the items that pass their checks together. If an unexpected error occurs, nothing in the request is applied: items that failed their checks keep their errors, and the other items fail with
500 UNCATCHED. Send the same request again. Rename requests apply each item separately, in request order. For details, see Bulk Responses.
Create Targetings in Bulk
Creates up to 100 targetings, each with or without options.Request
context-targeting:write scope.
Request Body
Across all items, a request can include up to 100 options, counting sub-options, and up to 10,000 Context IDs.
Example Request
Example Response
Thedata of a successful item is the new targeting object, including its options. In this example, the third item fails because a targeting named “News Sections” already exists.
TARGETING_NAME_DUPLICATE has detail.duplicateOfIndex, the index of that item, instead of detail.existingId.
Rename Targetings in Bulk
Renames up to 100 targetings.Request
context-targeting:write scope.
Request Body
Example Request
Example Response
Thedata of a successful item is the renamed targeting object, without categories.
Delete Targetings in Bulk
Deletes up to 100 targetings and all of their options.Request
context-targeting:write scope.
Request Body
Example Request
Example Response
Thedata of a successful item has only the _id of the deleted targeting. In this example, an approved campaign that hasn’t ended includes one of the targeting’s options, so the targeting isn’t deleted.