Skip to main content
An option group is a targeting option that groups other options, called sub-options. With the API, you can create option groups, add and move sub-options, and choose whether advertisers can select sub-options individually. The requests on this page need an API key with the 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 is sport, 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.
In the option object, option groups and sub-options have these fields: To read an option group:
  • Get an Option returns only the option group’s own Context IDs in contexts, paged with offset and limit (ownContextCount in total). Read each sub-option’s Context IDs from the sub-option.
  • When childCount is more than 50, list all sub-options with List Options and the parent query parameter set to the option group ID.
To rename an option group or a sub-option, or to change its Context IDs, use Update an Option as you would for any option. For an option group, 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 send type: "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 children or one Context ID in contexts. An option group with neither fails with 400 TARGETING_CATEGORY_NOT_SUPPORTED. So does type: "atomic" with children.
  • An item in children accepts only name and contexts. 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.
You can also create option groups when you create a targeting, with the same fields in each categories item, or with Add Options in Bulk.

Example Request

To create an option group with only its own Context IDs, keep type: "collection" and leave out children:

Example Response

The API returns 201 with the new option group.

Add an Option to an Option Group

To add a new sub-option to an existing option group, send parent with the option group ID to the Add an Option endpoint.
  • parent must be a top-level option group in the same targeting. If the targeting has no option with that ID, the request fails with 404 TARGETING_CATEGORY_NOT_FOUND. If the option isn’t an option group, it fails with 400 TARGETING_CATEGORY_NOT_SUPPORTED.
  • The new option is a regular option. type: "collection", children, or exposeChildren together with parent fails with 400 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.
To put an existing option into an option group, see Move or Detach an Option.

Request

Path Parameters

Request Body

Example Request

Example Response

The API returns 201 with the new sub-option.

Move or Detach an Option

Send parent 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.
  • null detaches 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. parent on an option group fails with 400 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_FOUND or 400 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.
The lock applies even when the option got its Required Include, Required Exclude, or campaign include or exclude automatically, for example from its option group when it was detached or when the option group was deleted. Until that setting is removed, you can’t move the option back under an option group with the API. To keep options in an option group, create them with parent or children from the start.

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:
To move it back under Sports, send the option group ID instead:

Example Response

The API returns 200 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. Set exposeChildren 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.
  • exposeChildren doesn’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 with 400 TARGETING_CATEGORY_NOT_SUPPORTED. Send true or false; null fails with 400.
  • 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 returns 200 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_EXCEEDED and nothing is deleted.
Campaigns don’t block the deletion. If the option group has no sub-options, campaigns that included it lose that condition. See Effects on Ad Products and Campaigns.
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 returns 200 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 children count toward the per-request and per-targeting option limits. See Limits.
Own Context IDs are unique among option groups
  • 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 add or set. A conflict fails with 400 TARGETING_COLLECTION_CONTEXT_DUPLICATED, and detail.conflicts lists up to 20 of the conflicting Context IDs with the option groups that already have them. See Error Codes.
An option group can’t become empty 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.limit is the limit, and detail.count is the number of option groups and sub-options in your request.
  • Renaming an option group, changing its own Context IDs, and setting exposeChildren don’t count as option group items.
Don’t delete an option group and its sub-options in the same bulk request The result depends on their order in 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.