sport, baseball, and soccer. In API paths and fields, an option is a category, and its Context IDs are contexts.
An option has one of two types:
atomic: a list of Context IDs.collection: an option that matches its own Context IDs and those of its sub-options. See Option groups.
https://lake.adrop.io. For authentication and request format, see Basic Information.
Option Object
The endpoints on this page return options in this shape. The object holds the number of Context IDs, not the Context IDs themselves. To read them, use Get an Option.
Fields that don’t apply to an option are omitted.
List Options
Returns the options of a targeting page by page, in ascending_id order (roughly the order they were created). Option groups and sub-options are included. Each item is an option object.
Request
context-targeting:read scope.
Path Parameters
Query Parameters
Example Request
Example Response
next=01JAB3XK5RA1B2C3D4E5F6G7H8.
- The last page has no
next. If you follownextuntil it’s absent, you get every option exactly once. - A page can have fewer items than
limiteven when more pages follow. Stop only whennextis absent. - There’s no search by name. Filter the items by
name,parent, orchildrenon your side.
Get an Option
Returns an option with a page of its Context IDs.Request
context-targeting:read scope.
Path Parameters
Query Parameters
Example Request
Example Response
- To read all Context IDs of an option, increase
offsetbylimituntiloffsetreachescontextCount. - For an option group,
contextsholds only the option group’s own Context IDs, so page through them up toownContextCount. To read the Context IDs of a sub-option, get the sub-option.
Add an Option
Adds an option to an existing targeting. You can add a regular option, an option group, or a sub-option of an existing option group.Request
context-targeting:write scope. The response is 201 with the new option object.
Path Parameters
Request Body
The server issues all IDs. A body with
_id or any other field not listed here fails with 400.
These combinations fail with 400 TARGETING_CATEGORY_NOT_SUPPORTED, and nothing is created:
- An option group with no sub-options and no Context IDs of its own
type: "atomic"withchildrenexposeChildrenon a regular optionparentwithtype: "collection",children, orexposeChildren. An option added to an option group is always a regular optionparentset to an option that isn’t a top-level option group
Example Request
Example Response
A new top-level option can be added to the ad products that use the targeting, and to their campaigns. See Effects on Ad Products and Campaigns.
For all error codes and the error format, see Error Codes.
Update an Option
Renames an option, changes its Context IDs, moves it into, out of, or between option groups, or changes whether an option group shows its sub-options to advertisers.Request
context-targeting:write scope. The response is 200 with the updated option object.
Path Parameters
Request Body
All fields are optional. Send only the fields you want to change. Fields you omit stay as they are.
These rules apply to the body:
contextsmust includeadd,remove, orset, andsetcan’t be combined withaddorremove. Otherwise the request fails with400.parentcan’t be combined withcontexts. Move or detach an option in one request and change its Context IDs in another.parentcan be combined withname. If the move fails, the name doesn’t change either.- Only
parentacceptsnull.nullinname,contexts,exposeChildren,add,remove, orsetfails with400. To leave a field unchanged, omit it. - An option group can’t be moved.
parenton an option group fails with400 TARGETING_CATEGORY_NOT_SUPPORTED, and so doesexposeChildrenon a regular option. - For an option group,
contextschanges its own Context IDs. Removing all own Context IDs of an option group that has no sub-options fails with400 TARGETING_CATEGORY_NOT_SUPPORTED. name,contexts, andexposeChildrenare written together. If the Context ID change fails, the name andexposeChildrendon’t change. If you send bothaddandremove,addis applied first, so the added Context IDs stay even ifremovefails.
add/remove and set, see Updating Context IDs.
Example Request
Example Response
Delete an Option
Deletes an option and its Context IDs.- Deleting an option group promotes its sub-options to the top level, and they take over the option group’s settings in ad products and campaigns. If the option group had Context IDs of its own, they stop matching. See Delete an option group.
- You can’t delete the last sub-option of an option group that has no Context IDs of its own. Delete the option group instead.
Request
context-targeting:write scope. The response is 200 with the ID of the deleted option.
Path Parameters
Example Request
Example Response
Bulk Operations
The bulk endpoints add, update, or delete up to 5,000 options in one request. They require thecontext-targeting:write scope.
- Unless the request fails as a whole, each bulk endpoint returns
200with a result for each item, in request order. Checksuccesson each result. A failed item has anerror. See Bulk Responses. - A request with an invalid body fails as a whole with
400, even if only one item is invalid. Examples are a Context ID that breaks the Context ID Rules,setcombined withadd, or a field that isn’t accepted. - API writes for a project are processed one at a time. Send bulk requests one after another, not in parallel. See Concurrent Writes.
Option group items are:
- Add: items that create an option group (
type: "collection"orchildren) and items withparent. - Update: items with
parent,nullincluded. - Delete: IDs of option groups and sub-options.
400, and nothing in it is applied. If a delete request has more than 150 option groups and sub-options, the error is TARGETING_CATEGORY_TREE_ITEMS_LIMIT_EXCEEDED, with the limit in detail.limit and the number of option groups and sub-options in your request in detail.count. To upload a large set, such as tens of thousands of options, send requests of up to 5,000 items one after another.
Add Options in Bulk
Adds options to existing targetings. Each item can add to a different targeting.Request
Request Body
A successful item has the new option object in
data.
Example Request
Example Response
The targeting already has an option named “Sports”, so only the third item fails.Update Options in Bulk
Updates options. Each item can change a different option.Request
Request Body
- Each
_idcan appear only once per request. A repeated_idfails the whole request with400, so put all changes for one option into one item. - Items are applied separately and can run at the same time. Results are still returned in request order.
- A name that an earlier item frees can be used by a later item in the same request.
data.
Example Request
Example Response
Delete Options in Bulk
Deletes options. The same rules as Delete an Option apply to each ID.Request
Request Body
A successful item has the ID of the deleted option in
data.
Example Request
Example Response
Context ID Rules
These rules apply to every Context ID you send, incontexts, children, add, remove, and set.
If any Context ID in a request breaks these rules, the whole request fails with
400.
The same Context ID can be in more than one option. A request with that Context ID matches all of those options. The exception is an option group’s own Context IDs, which can’t be an own Context ID of another option group in the project. See Constraints.
Context IDs are also limited by count and size:
A change that would put an option or the project over its limit fails with
400 TARGETING_CONTEXT_LIMIT_EXCEEDED. These limits are checked only when a change makes an option or the project larger, so a change that only removes Context IDs is never blocked. A request with more than 10,000 Context IDs fails as a whole with 400. For all limits, see Limits.
Updating Context IDs
Change Context IDs withadd/remove or with set in Update an Option or Update Options in Bulk.
add, remove, and set give the same result if you send the same request again, so you can resend them after a timeout. See Retries and Duplicate Requests.
More than 10,000 Context IDs
A request can carry up to 10,000 Context IDs, so set can’t replace a longer list in one request. Sync the option this way instead:
- Read the option’s current Context IDs with Get an Option, paging with
offsetandlimit. - Compare them with your list.
- Send only the differences with
addandremove, up to 10,000 Context IDs per request, one request after another.
set requests. Each set replaces all Context IDs, so a later set drops the Context IDs of an earlier one. Even one set followed by add requests leaves the option with only part of its list between requests, and ad serving can pick up that partial list.
Changes reach ad serving after a short delay. To check whether a change has been loaded, see When Changes Take Effect.
Effects on Ad Products and Campaigns
Ad products and campaigns select options, so changing an option can change where campaigns serve. Adding or removing Context IDs changes the pages where campaigns that include or exclude the option can serve. New top-level options When you add a top-level option, either a regular option or an option group, ad products that have settings for the targeting also get the option:- If an ad product sets every current top-level option of the targeting to Required Include, the new option is also set to Required Include, and the product’s campaigns that haven’t ended include it too. Required Exclude works the same way.
- Otherwise, the new option is added to the ad product as an option advertisers can select. This is the case when some top-level options aren’t required, or when they mix Required Include and Required Exclude. Campaigns don’t change.
400 AD_PRODUCT_TARGETING_POLICY_LIMIT_EXCEEDED.
In a bulk request, every new top-level option for that targeting fails, and the other items are applied. Reduce the required options of the ad product in the console, then send the request again. The same limit applies when you delete an option group or detach a sub-option, because the option group’s settings are copied to its sub-options.
Deleting options
Deleting an option isn’t blocked when campaigns use it, unlike deleting a targeting. The option is removed from the campaigns that select it. If it was the only option from the targeting that a campaign included, the campaign no longer requires any of the targeting’s Context IDs. Instead of stopping, it can serve on requests with other Context IDs or with none.
Before you delete an option, check whether campaigns use it. In the console, an option with campaigns booked has the In Use status. See Managing Targeting. Change or end those campaigns before you delete the option.
Excluding Context IDs
An option only lists the Context IDs to match. There’s no condition for “not in this option”. To keep ads off certain pages, put the Context IDs of those pages in an option and exclude the option in the ad product or campaign, for example with Required Exclude on the ad product. Don’t build an option that lists every other Context ID.