gads_link_shared_set_to_campaign
Google Ads write medium risk
Part of the Search Terms Agent.
What it does
Attach (or detach) a shared negative set to a campaign via CampaignSharedSet. PREVIEW->APPROVE->COMMIT: builds the CampaignSharedSet create (attach) or remove (detach) op, previews via validate_only=true naming the set and campaign and the broad effect (all negatives in the set apply to/stop applying to the campaign), waits for approval, commits with validate_only=false + partial_failure=true, returns the CampaignSharedSet resource_name + timestamp. NEGATIVE_KEYWORDS/NEGATIVE_PLACEMENTS sets attach at campaign level only. Returns {success, data, count, warnings}. 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. validate_only=true forces another preview; validate_only=false alone never commits.
When to use it
Use to apply a reusable negative set to a campaign (or remove it). State that all negatives in the set immediately affect the campaign's traffic. Get explicit approval before linking.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
customer_id | string | yes | 10-digit CID, dashes stripped. |
shared_set_id | string | yes | SharedSet ID/resource_name to attach/detach. |
campaign_id | string | yes | Campaign to attach the set to (or detach from). |
action | string | no | ATTACH (default) or DETACH (enum-normalized); DETACH issues a remove on the CampaignSharedSet link. |
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
Non-content-policy; require approval and log the actor. Attaching applies every negative in the set to the campaign at once — preview the breadth of suppression.
Reminder
Log the actor/reason for the link change; never expose tokens.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
CUSTOMER_NOT_FOUND | Account not found/linked. | Verify CID/authorization. | no |
TOKEN_REVOKED | Authorization expired/revoked. | needs_reauth. | no |
SHARED_SET_NOT_FOUND | Shared set not found or removed. | Verify the shared_set_id. | no |
CAMPAIGN_NOT_FOUND | Campaign not found. | Verify the campaign_id. | no |
INVALID_ARGUMENT | Link already exists, or the set type is not valid at campaign level for this campaign type. | Surface Google's message; if already attached, treat as a no-op. | no |
MANAGER_ACCOUNT_NOT_SUPPORTED | Cannot mutate on a manager (MCC) account. | Target a child serving account. | no |
PERMISSION_DENIED | No write access / out of bearer scope. | Confirm role/scope. | no |
RESOURCE_EXHAUSTED | Rate/quota limit (HTTP 429). | Backoff 5/10/20s cap 60s; honor retryDelay. | yes |
INTERNAL_ERROR | Transient 5xx. | Retry once after backoff. | yes |
Edge cases
- Set already linked to the campaign -> idempotent; report as already attached.
- DETACH when not linked -> no-op; report not attached.
- Linking a NEGATIVE_PLACEMENTS set to a Search campaign -> no-effect/invalid combo; warn.
- validate_only clean still needs approval before commit.
- Empty set linked -> succeeds but suppresses nothing yet; warn.
- Expired token -> refresh once and retry.
- shared_set.member_count is lazily maintained by Google and can read 0 while shared_criterion rows exist — count shared_criterion rows for truth, never member_count.
- REMOVED shared sets drop out of status-filtered listings while their shared_criterion rows remain queryable — when auditing, include REMOVED status and SELECT shared_set.id on shared_criterion queries to attribute orphaned criteria.