context-targeting:write scope. Reading option groups needs context-targeting:read. See Prerequisites.
The examples build a Sports option group with the sub-options Baseball and Soccer in the News Sections targeting (01JAB3XK5Q8V7M2N4P6R9T0W1Y). They assume the targeting has no other option named Sports, because option names must be unique within a targeting.
What Is an Option Group
An option group matches its own Context IDs and the Context IDs of its sub-options. With the structure below, a campaign that includes Sports matches ad requests whose Context ID issport, baseball, or soccer.
- One level only: Sub-options are always regular options (
type: "atomic"). An option group is always a top-level option and can’t contain another option group. - Never empty: An option group needs at least one sub-option or one Context ID of its own.
- Unique own Context IDs: An option group’s own Context IDs can’t also be own Context IDs of another option group in the project. See Constraints.
- Names: Option group and sub-option names follow the name rules and must be unique within the targeting, including option groups and sub-options. A duplicate fails with
409 TARGETING_CATEGORY_NAME_DUPLICATE.
To read an option group:
- Get an Option returns only the option group’s own Context IDs in
contexts, paged withoffsetandlimit(ownContextCountin total). Read each sub-option’s Context IDs from the sub-option. - When
childCountis more than 50, list all sub-options with List Options and theparentquery parameter set to the option group ID.
contexts changes only its own Context IDs. Changes reach ad serving after a short delay. See When Changes Take Effect.
Create an Option Group
Use the same endpoint as Add an Option and sendtype: "collection", children, or both. Each item in children becomes a new sub-option, created together with the option group.
Request
Path Parameters
Request Body
- Send at least one item in
childrenor one Context ID incontexts. An option group with neither fails with400 TARGETING_CATEGORY_NOT_SUPPORTED. So doestype: "atomic"withchildren. - An item in
childrenaccepts onlynameandcontexts. A sub-option can’t have sub-options of its own. - If one of the option group’s own Context IDs is already an own Context ID of another option group in the project, the request fails with
400 TARGETING_COLLECTION_CONTEXT_DUPLICATED. See Constraints. - A new option group is a new top-level option, so Effects on Ad Products and Campaigns applies to it as to any new option.
categories item, or with Add Options in Bulk.
Example Request
type: "collection" and leave out children:
Example Response
The API returns201 with the new option group.
Add an Option to an Option Group
To add a new sub-option to an existing option group, sendparent with the option group ID to the Add an Option endpoint.
parentmust be a top-level option group in the same targeting. If the targeting has no option with that ID, the request fails with404 TARGETING_CATEGORY_NOT_FOUND. If the option isn’t an option group, it fails with400 TARGETING_CATEGORY_NOT_SUPPORTED.- The new option is a regular option.
type: "collection",children, orexposeChildrentogether withparentfails with400 TARGETING_CATEGORY_NOT_SUPPORTED. - The option group starts matching the new option’s Context IDs. Campaigns that include the option group now also target them, and campaigns that exclude it now also exclude them. Ad product settings don’t change.
Request
Path Parameters
Request Body
Example Request
Example Response
The API returns201 with the new sub-option.
Move or Detach an Option
Sendparent to Update an Option to change where an option sits.
- An option group ID moves the option under that option group, from the top level or from another option group.
nulldetaches a sub-option to the top level.
The option group that receives the option starts matching its Context IDs, and the option group that the option leaves stops matching them.
- You can’t move an option group.
parenton an option group fails with400 TARGETING_CATEGORY_NOT_SUPPORTED. - The destination must be a top-level option group in the same targeting. Otherwise the request fails with
404 TARGETING_CATEGORY_NOT_FOUNDor400 TARGETING_CATEGORY_NOT_SUPPORTED. - You can’t move or detach the last sub-option of an option group that has no Context IDs of its own. The request fails with
400 TARGETING_CATEGORY_NOT_SUPPORTED.
Request
Path Parameters
Request Body
parent can’t be combined with contexts. Change Context IDs in a separate request.
Example Request
Detach Soccer to the top level:Example Response
The API returns200 with the updated option. A detached option has no parent.
Show Sub-Options to Advertisers
By default, advertisers can select an option group only as a whole. SetexposeChildren to true to let advertisers include or exclude each sub-option on its own when they book a campaign.
- Advertisers can select sub-options only when the ad product offers the option group as Free Selection. See Selling Targeting.
exposeChildrendoesn’t change what the option group matches. Changing it doesn’t modify existing ad products or campaigns.- Only option groups accept
exposeChildren. Sending it for any other option fails with400 TARGETING_CATEGORY_NOT_SUPPORTED. Sendtrueorfalse;nullfails with400. - You can also set it when you create the option group.
Request
Path Parameters
Request Body
You can send
name and contexts in the same request.
Example Request
Example Response
The API returns200 with the updated option group.
Delete an Option Group
Delete an option group with Delete an Option. Its sub-options aren’t deleted:- Sub-options move to the top level and take over the option group’s settings in ad products and campaigns. For example, if an ad product sets Sports as Required Include, Baseball and Soccer become Required Include, and a campaign that included Sports now includes Baseball and Soccer.
- The option group’s own Context IDs are deleted and stop matching. In the example, campaigns that included Sports no longer match
sport. - If taking over the settings would give an ad product more than 500 options set as Required Include or Required Exclude, the request fails with
400 AD_PRODUCT_TARGETING_POLICY_LIMIT_EXCEEDEDand nothing is deleted.
In the console, Delete on a group also deletes its sub-options. Deleting an option group with the API works like Ungroup in the console: its sub-options stay as top-level options.
Request
Path Parameters
Example Request
Example Response
The API returns200 with the ID of the deleted option group.
Constraints
Structure- An option group can’t be moved, and an option’s type can’t change after it’s created. To group existing options, create an option group and move the options under it. A new option group can’t be empty, so create it with a Context ID of its own or a new sub-option.
- Sub-options created in
childrencount toward the per-request and per-targeting option limits. See Limits.
- An option group’s own Context IDs can’t be own Context IDs of another option group in the project, in any context targeting. Regular options and sub-options can share Context IDs with any option.
- The rule applies when you create an option group and when you add own Context IDs to an option group with
addorset. A conflict fails with400 TARGETING_COLLECTION_CONTEXT_DUPLICATED, anddetail.conflictslists up to 20 of the conflicting Context IDs with the option groups that already have them. See Error Codes.
An option group with its own Context IDs can lose all of its sub-options. It stays as an option group with only its own Context IDs.
Option group items per bulk request
In one option bulk request, at most 150 items can be option group items. A request with more fails as a whole with
400, and nothing is applied. Split the items and send the requests one after another.
- For a bulk delete, the error code is
TARGETING_CATEGORY_TREE_ITEMS_LIMIT_EXCEEDED.detail.limitis the limit, anddetail.countis the number of option groups and sub-options in your request. - Renaming an option group, changing its own Context IDs, and setting
exposeChildrendon’t count as option group items.
ids:
- Option group first: The sub-options move to the top level, take over the option group’s settings, and are then deleted as top-level options. Campaigns that included the option group can lose that condition.
- Sub-options first: If the option group has no Context IDs of its own, deleting the last sub-option fails with
400 TARGETING_CATEGORY_NOT_SUPPORTED. That option then moves to the top level when the option group is deleted.