gads_apply_label
Google Ads write low risk
Part of the Account Structure Agent.
What it does
Apply a label to one or more campaigns, ad groups, or ads (entity_type AD_GROUP_AD; alias AD) (CampaignLabelService / AdGroupLabelService / AdGroupAdLabelService) in bulk via create operations. entity_type selects the service. For ads, each target is {ad_group_id, ad_id}. WRITE with preview->approve->commit: preview = mutate validate_only=true + diff (label, entity_type, target count/IDs) + preview_id; commit = the same call plus that preview_id after the user approves in a later message (the server then runs the real mutate) + audit. Returns {label_id, entities_labeled, ids}. Bulk-capable; uses partial_failure on commit so already-labeled entities don't fail the batch. PREVIEW SEMANTICS: the first call (no preview_id) is sent to the Google Ads API in validation mode — field, enum, policy and permission errors surface AT PREVIEW, nothing is changed, and the response returns a preview_id. To apply, show the preview to the user, get their approval, and re-call with that preview_id and IDENTICAL arguments within 30 minutes; changed arguments or an expired token fail closed to a fresh preview.
When to use it
Applying labels. Use to bulk-tag campaigns/ad groups/ads. Preview the target list, confirm the entity set, then commit. Good for grouping entities for later reporting or bulk actions.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
customer_id | string | yes | 10-digit CID; strip dashes. |
label_id | string | yes | ID of the label to apply (create via gads_create_label). |
entity_type | string | yes | CAMPAIGN, AD_GROUP, or AD_GROUP_AD (alias: AD; case-insensitive) — selects the label link resource. |
campaign_ids | array | no | Campaign IDs (entity_type=CAMPAIGN). |
ad_group_ids | array | no | Ad group IDs (entity_type=AD_GROUP). |
ad_group_ad_ids | array | no | For entity_type=AD_GROUP_AD. Each item may be {ad_group_id, ad_id}, the string 'adGroupId~adId', or a full ad_group_ad resource_name (customers/<cid>/adGroupAds/<ag>~<ad>) - all three are accepted. |
manager_id | string | no | Optional MCC login-customer-id. |
validate_only | boolean | no | Optional. true forces another preview even with a preview_id; false is DEPRECATED and no longer commits — only a valid preview_id applies the write. |
preview_id | string | no | Omit it to preview: nothing is applied, and the call returns a preview_id bound to this exact request. Pass it only after the user approves that preview in a later message, with the same arguments (leave out validate_only, and add any confirmation flag the preview names). Single-use, expires in 30 minutes; changed arguments need a fresh preview. |
Safeguards
A change in two steps. The first call previews and changes nothing; Claude shows you the preview and applies it only after you approve, within 30 minutes and with the same arguments. Every applied change goes to the audit log. How changes are approved.
Policy
Labeling is organizational; do not use labels to mark or segment entities by protected-class targeting. No spend effect.
Reminder
Organizational only; no spend/targeting change and no sensitive segmentation.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
PARTIAL_FAILURE | Some entities were already labeled or invalid while others succeeded. | Report failed indices (e.g., LABEL_ALREADY_APPLIED); the rest succeeded. | no |
VALIDATION_ERROR | No target IDs provided for the chosen entity_type. | Provide the matching ID list for the entity_type. | no |
NOT_FOUND | Label or target entity does not exist. | Confirm label_id and entity IDs. | no |
TOKEN_REVOKED | OAuth token expired/revoked. | Refresh and retry once; else prompt reconnect (needs_reauth). | yes |
PERMISSION_DENIED | No access or out-of-bearer-scope write. | Confirm access and write scope; else refuse. | no |
RESOURCE_EXHAUSTED | Rate/quota exceeded (HTTP 429). | Backoff 5/10/20s cap 60s, then retry. | yes |
INTERNAL_ERROR | Transient Google server error (5xx). | Retry after backoff. | yes |
Edge cases
- Applying a label already on an entity -> per-row LABEL_ALREADY_APPLIED (partial failure), not a batch failure.
- Bulk op count must stay within the 10,000 mutate-op cap; chunk larger lists.
- entity_type=AD requires {ad_group_id, ad_id} pairs, not bare ad IDs.
- Mismatched entity_type vs provided IDs -> VALIDATION_ERROR.
- Preview changes nothing; preview_id TTL expiry -> re-preview; expired token -> refresh once and retry.