Skip to documentation content
CookieBeam

Authentication

Create and use CookieBeam API keys, choose scopes, and understand live, test and publishable keys.

Last updated:

The public API authenticates requests with API keys. API access requires a plan that includes the API feature; on a plan without it, a valid key is rejected with a plan_required error (HTTP 403).

There are two kinds of key:

  • Secret keys (cb_live_..., cb_test_...) authenticate server-to-server calls and the MCP server. Keep them on your servers.
  • Publishable keys (cb_pub_live_..., cb_pub_test_...) are public by design. They can only record form consent from the browser, and only from the origins they list. See Publishable keys.

Assistants sign in with OAuth

AI assistants such as ChatGPT, Claude and other MCP clients don't need an API key. They connect to the MCP server with OAuth 2.1 sign-in: the assistant opens CookieBeam's sign-in page, you sign in as usual, choose an access level and approve. Sign-in works on every plan and doesn't need the API feature.

  • Two access levels. Read-only lets the assistant read banners, scans, designs and consent analytics. Read and change adds starting scans, editing drafts and settings, publishing, and creating or deleting banners. The connection acts as the member who approved it and never does more than that member can do in the dashboard.
  • Bound to the MCP endpoint. Sign-in access tokens (cbo_at_...) work only on /api/mcp. The REST API refuses them with HTTP 401 unauthorized; use an API key there.
  • Revoking. Every connection is listed under Account > Connected apps, where you can revoke it. A revoked connection stops working within a minute.

Create a key

Team owners create, rotate and revoke secret keys in the dashboard under Settings > API keys. Each key has a name, an environment, a list of scopes, and an expiry. Keys always expire: the default is 90 days for live keys and 30 days for test keys, and you can choose any lifetime from 1 to 365 days. A team can have at most 20 active keys.

The full key is displayed exactly once at creation. CookieBeam stores only a SHA-256 hash of the key's validator segment, so a lost key cannot be recovered — revoke it and create a new one.

Key format

Secret keys are prefixed by environment followed by 64 lowercase hexadecimal characters:

cb_live_<64 hex chars>
cb_test_<64 hex chars>

A key that does not match this format, or whose prefix does not match the environment it was created in, is rejected as invalid_key.

Send the key

Send the key as a bearer token in the Authorization header. The curl examples in this reference read it from the COOKIEBEAM_API_KEY environment variable, so the key never appears in your shell history or scripts:

curl https://cookiebeam.com/api/v1/banners \
 -H "Authorization: Bearer $COOKIEBEAM_API_KEY"

Who a key acts for

Most endpoints treat a key as a team-level principal: it acts as the team, not as the member who created it, and per-member banner access lists do not restrict it. Treat keys with the same care as team administrator credentials.

The banner design endpoints (everything under /api/v1/banners/{bannerId}/...) are stricter. There the key acts for the member who created it, and every call re-checks that member's current permissions:

  • If the creator is no longer an active member of the team, the call fails with HTTP 403 key_owner_inactive. Ask a team admin to issue a new key.
  • If the creator cannot see that part of the banner, the call fails with HTTP 404 not_found, the same answer as for another team's banner.
  • If the creator can see it but cannot make the change (for example, they can view designs but not edit them), the call fails with HTTP 403 insufficient_permission. details names the sub-section, the required level and the level held.

A permission change in the dashboard therefore takes effect on that member's keys at once.

Live vs test keys

Test keys can read but not change live data. The rule follows the access level of the scope an endpoint requires:

  • read and export scopes work with test keys.
  • write, publish, erase and admin scopes are refused with HTTP 403 test_key_read_only.

The banner design endpoints apply a finer rule, because their writes change a draft rather than what visitors see. A test key may read and may change drafts (create or update themes and design settings). It may not delete or duplicate a theme, run a banners:admin action, store or remove a logo file, or start a site capture or style match. Those calls fail with HTTP 403 test_key_production_forbidden.

Use test keys to explore the API and to build against drafts; use live keys for anything that changes production data.

Scopes

Each key carries an explicit allow-list of scopes. An endpoint declares the scope it requires; if the key is missing one, the request fails with HTTP 403 and the error code missing_scope, with the missing scopes named in the message.

Scopes are grouped by resource. Active scopes are required by at least one endpoint or MCP tool. Reserved scopes are part of the scope vocabulary but no endpoint uses them yet.

ScopeStatusGrants
banners:readActiveList and read banners and their embed code (GET /api/v1/banners, MCP banner tools). Also grants every banners.<area>:read scope
banners.design:readActiveRead banner themes and design settings
banners:writeActiveCreate banners over REST (POST /api/v1/banners), change banner settings (PATCH /api/v1/banners/{bannerId}/settings, MCP update_banner_settings; includes switching a banner on or off) and drafts. Also grants every banners.<area>:write scope
banners.design:writeActiveChange banner themes and design settings (drafts only)
banners:publishActivePublish banner changes to the live site (MCP preview_publication, publish_banner and publish_cookie_policy, and their REST paths)
banners:adminActiveCreate banners through MCP (create_banner), delete banners (DELETE /api/v1/banners/{bannerId}, MCP delete_banner; deleting also erases their consent records), duplicate and delete themes, set the default theme
consent:readActiveResolve cross-device consent subjects
consent:writeActiveLog consent and write or delete cross-device consent state
consent:exportReservedExport consent records
consent:forms:readActiveSearch and read form consent proofs
consent:forms:writeActiveRecord form consent proofs (given, confirmed, withdrawn)
consent:forms:exportActiveBulk-export form consent proofs with receipts
consent:forms:eraseActiveErase every form consent proof of a person
preferences:readActiveRead marketing preference topics and a person's preferences
preferences:writeActiveManage topics, update a person's preferences and issue preference links
preferences:eraseActiveErase the marketing preference history of a person
scanner:readActiveRead scans, scan results and the discovery inventory (MCP tools)
scanner:writeActiveStart scans (MCP start_scan and POST /api/v1/banners/{bannerId}/scans)
analytics:readActiveRead consent analytics (MCP tool)
team:readReservedRead team members
team:writeReservedManage team members
webhooks:readReservedRead webhook configuration
webhooks:writeReservedManage webhook configuration
audit:readReservedRead the audit log

banners:read and banners:write are umbrella scopes for the banner design endpoints: a key holding banners:read passes a check for banners.design:read, and banners:write passes banners.design:write. banners:write does not grant banners:publish or banners:admin. Grant the narrower banners.design:* scopes when a key only needs design access.

Rules when you create or rotate a key:

  • New keys can only request active scopes. Requesting a reserved scope is rejected (BAD_REQUEST) and the message names the reserved scopes. When an endpoint ships for a reserved scope, the scope becomes active.
  • Existing keys keep their scopes. A key that already holds a reserved scope keeps authenticating, and rotating it copies its scopes unchanged.
  • A key cannot exceed its issuer. Every scope maps to a set of dashboard permissions; you can only grant a scope whose permissions you hold yourself. This is checked on create and on rotate (FORBIDDEN otherwise), and the dashboard disables scopes you cannot grant.

Grant only the scopes an integration actually uses. A reporting job needs banners:read and nothing else; keep write and erase scopes off keys that ship to CI or shared environments.

A key can optionally be limited to specific banners and to specific banner environments (for example production or staging). Leave both empty and the key covers every banner and environment of the team, which is how all keys created before restrictions existed behave.

  • Banners. A banner outside the key's list behaves exactly like a banner of another team: single-banner requests return HTTP 404 not_found (MCP tools report Banner not found), and lists such as GET /api/v1/banners and the MCP list_banners and list_scans tools only include the allowed banners. A banner-restricted key cannot create banners (HTTP 403, code key_restricted), because the new banner would sit outside its own list.
  • Form consent proofs. A banner-restricted key only sees form consent proofs recorded for its banners; proofs recorded without a banner are hidden from it. It must pass a bannerId from its list when it records a proof, and it cannot erase a person's proofs, because erasure covers every banner of the team (both HTTP 403, code key_restricted).
  • Environments. Environment-specific results, such as the per-environment script URLs from the MCP get_embed_code tool, only include the allowed environments. The install snippet, which serves the production environment, is only returned when production is allowed.
  • Who can set them. You can only restrict a key to banners you can access yourself; every banner must belong to your team and every environment must exist on one of the selected banners. Restrictions can be changed on an existing key from the dashboard without re-issuing it, and rotating a key keeps them.

Publishable keys

A publishable key lets a browser record form consent without exposing a secret key. It is meant for the forms snippet and is created per site, by a team owner, under Form consents on the banner's Consent tab. Form consent is gated; see Form consent for availability.

cb_pub_live_<64 hex chars>
cb_pub_test_<64 hex chars>

What a publishable key can do:

  • It authenticates only POST /api/v1/consent/forms, and only for event: "given". Confirmations and withdrawals need a secret key. Sent to any other endpoint, it is refused with HTTP 403 publishable_key_not_allowed.
  • The request's Origin header must be one of the key's allowed origins, otherwise HTTP 403 origin_not_allowed. Origins must be https; test publishable keys may also list http://localhost origins.
  • It can be sent as a bearer token or as the key query parameter. The snippet uses the query parameter (and idempotencyKey for the idempotency key) so the browser does not need a CORS preflight.
  • A test publishable key validates the request and stores nothing: the response is HTTP 200 with test: true.
  • It has its own rate limits: 600 requests per minute per key, and 30 requests per minute per key from one client IP.

Authentication errors

All authentication errors use the standard error envelope.

HTTP statusCodeCause
401invalid_keyThe key is malformed, unknown, or its prefix does not match its environment
401revoked_keyThe key has been revoked, or its team was deleted
401expired_keyThe key has passed its expiry date
401unauthorizedThe endpoint requires an API key and none was sent
403plan_requiredThe team's plan does not include API access
403missing_scopeThe key lacks a scope the endpoint requires
403test_key_read_onlyA test key was used for a write, publish, erase or admin operation
403test_key_production_forbiddenA test key was used for a banner design operation it may not run
403key_owner_inactiveBanner design endpoints: the member who created the key is no longer an active member
403insufficient_permissionBanner design endpoints: the member who created the key lacks the permission the operation needs
403key_restrictedA key restricted to specific banners was used to create a banner, to record a form consent proof without one of its banners, or to erase form consent proofs
403publishable_key_not_allowedA publishable key was sent to an endpoint that needs a secret key, or used for a confirmation or withdrawal
403origin_not_allowedA publishable key was used from an origin it does not list

Failed authentication attempts are limited to 10 per minute per client IP. Past that budget, further attempts return HTTP 429 with the code rate_limited and a Retry-After header, even if the credentials are wrong. This slows down key guessing; if you see it during legitimate troubleshooting, wait for the window to pass.

AltStyle によって変換されたページ (->オリジナル) /