Skip to main content
A targeting holds the targeting options that advertisers choose from when they book a campaign. Use these endpoints to manage targetings. To manage the options inside a targeting, see Targeting Options.
  • Read endpoints require the context-targeting:read scope, and write endpoints require context-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

Requires the 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

Requires the context-targeting:read scope.

Path Parameters

Query Parameters

Example Request

Example Response

200 with a targeting object:
To read the Context IDs of an option, use Get an Option. Errors

Create a Targeting

Creates a context targeting. You can create its options in the same request.

Request

Requires the 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 _id fails with 400.
  • Items in categories can’t include parent. A request that includes it fails with 400. 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.
For how option groups work, see Create an option group.

Example Request

Example Response

201 with the new targeting object, including its options:
Save the _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:
Creating isn’t idempotent. If a create request times out or fails with a 5xx error, you can send it again. If the first request had succeeded, the resend fails with 409 TARGETING_NAME_DUPLICATE, and detail.existingId is the ID of the targeting that the first request created. See Retries and Duplicate Requests.

Rename a Targeting

Changes the name of a targeting. Its options and Context IDs don’t change.

Request

Requires the 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.
Errors

Delete a Targeting

Deletes a targeting and all of its options, including option groups and sub-options.
You can’t delete a targeting while an approved campaign that hasn’t ended includes or excludes any of its options. The request fails with 400 TARGETING_LOCKED, and nothing is deleted. Deleting individual options isn’t blocked this way. See Delete an Option.

Request

Requires the context-targeting:write scope.

Path Parameters

Example Request

Example Response

200 with only the ID of the deleted targeting:
Errors

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 200 with a result for each item, even if every item fails. Some items can succeed while others fail, so check success for 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

Requires the 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

The data 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.
Items fail with the same errors as Create a Targeting. When the name belongs to a targeting that an earlier item in the same request created, 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

Requires the context-targeting:write scope.

Request Body

Example Request

Example Response

The data of a successful item is the renamed targeting object, without categories.
Items fail with the same errors as Rename a Targeting.

Delete Targetings in Bulk

Deletes up to 100 targetings and all of their options.

Request

Requires the context-targeting:write scope.

Request Body

Example Request

Example Response

The data 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.
Items fail with the same errors as Delete a Targeting.