> ## Documentation Index
> Fetch the complete documentation index at: https://docs.interchange.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Ensure GAM custom-targeting keys exist

> Idempotently create the named GAM custom-targeting keys on a Google Ad Manager-backed ad server source. Names already present in the source's synced GAM catalog are reported in `alreadyExisted` with no GAM call; truly-missing names are minted as FREEFORM, ACTIVE, `reportableType=ON` and returned in `created`. After minting, the source re-runs its custom-targeting sync inline so a follow-up `PUT /axe-keys` call (or equivalent for other signal protocols) sees the fresh key IDs on the same turn. Protocol-agnostic — currently used to mint AXE keys (axei / axex / axem) but reusable for TMP and future signal protocols.



## OpenAPI

````yaml /v2/storefront-api-v2.yaml post /esa/{esaId}/gam-custom-targeting-keys/ensure
openapi: 3.0.0
info:
  title: Scope3 Storefront API
  version: 2.0.0
  description: |-
    REST API for partners to manage storefronts, inventory sources, and billing.

    ## Authentication

    All endpoints require a Bearer token in the Authorization header:
    ```
    Authorization: Bearer your-api-key
    ```

    ## Base URL

    `https://api.interchange.io/api/v2/storefront`

    ## For AI Agents

    AI agents can use the MCP endpoint at `/mcp/v2/storefront` with three tools:
    - `initialize`: Start an MCP session
    - `api_call`: Make REST API calls
    - `ask_about_capability`: Learn about API features
servers:
  - url: https://api.interchange.io/api/v2/storefront
    description: Production server
security: []
tags:
  - name: Account
    description: Account management, service tokens, and preferences
  - name: Storefront
    description: Manage storefront and inventory sources
  - name: Storefront Agents
    description: List and manage registered sales, signals, and outcomes agents
  - name: Storefront Activity
    description: Audit log of configuration and inventory changes on the storefront
  - name: Storefront Billing
    description: Payout bank details and billing configuration for storefronts
  - name: AI Usage
    description: Storefront AI token usage visibility by model
  - name: MCP
    description: Model Context Protocol endpoints
paths:
  /esa/{esaId}/gam-custom-targeting-keys/ensure:
    post:
      tags:
        - Storefront Ad Server Buyer Routing
      summary: Ensure GAM custom-targeting keys exist
      description: >-
        Idempotently create the named GAM custom-targeting keys on a Google Ad
        Manager-backed ad server source. Names already present in the source's
        synced GAM catalog are reported in `alreadyExisted` with no GAM call;
        truly-missing names are minted as FREEFORM, ACTIVE, `reportableType=ON`
        and returned in `created`. After minting, the source re-runs its
        custom-targeting sync inline so a follow-up `PUT /axe-keys` call (or
        equivalent for other signal protocols) sees the fresh key IDs on the
        same turn. Protocol-agnostic — currently used to mint AXE keys (axei /
        axex / axem) but reusable for TMP and future signal protocols.
      operationId: ensureEsaGamCustomTargetingKeys
      parameters:
        - in: path
          name: esaId
          schema:
            description: >-
              Ad server source connection id. The wire field remains `esaId` for
              API compatibility.
            example: 123
            type: integer
            maximum: 9007199254740991
            minimum: 1
          required: true
          description: >-
            Ad server source connection id. The wire field remains `esaId` for
            API compatibility.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EnsureGamCustomTargetingKeysBody'
      responses:
        '200':
          description: Ensure GAM custom-targeting keys exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnsureGamCustomTargetingKeysResponse'
        '400':
          description: >-
            Ad-server-side failure surfaced as `VALIDATION_ERROR`; the
            `details.upstreamCode` field distinguishes the cause.
            `ADAPTER_PERMISSION_DENIED` — the source's GAM service account lacks
            the `CustomTargetingKey.write` scope required to create keys; the
            operator must either grant the service account a role with that
            scope (Trafficker or an equivalent least-privilege custom role) OR
            create the keys manually in GAM (Admin → Custom Targeting) as
            FREEFORM, then retry. Other `ADAPTER_*` upstream codes (e.g.
            `ADAPTER_KEY_LIMIT_EXCEEDED` when the network is at its
            custom-targeting key cap) also surface via this path — always branch
            on `details.upstreamCode`, not on the HTTP status.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: >-
            A key with the requested name was created between our sync and our
            create call (name-collision race) and the retry sync still can't see
            it. Refresh the ad server source and retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
components:
  schemas:
    EnsureGamCustomTargetingKeysBody:
      type: object
      properties:
        keys:
          minItems: 1
          type: array
          items:
            type: object
            properties:
              name:
                type: string
                minLength: 1
              displayName:
                type: string
                minLength: 1
            required:
              - name
              - displayName
      required:
        - keys
    EnsureGamCustomTargetingKeysResponse:
      type: object
      properties:
        created:
          type: array
          items:
            $ref: '#/components/schemas/GamCustomTargetingKeyEntry'
        alreadyExisted:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              keyId:
                type: string
              displayName:
                type: string
            required:
              - name
              - keyId
              - displayName
            additionalProperties: false
      required:
        - created
        - alreadyExisted
      additionalProperties: false
    ErrorResponse:
      description: Standard error response
      type: object
      properties:
        data:
          type: string
          nullable: true
          enum:
            - null
        error:
          $ref: '#/components/schemas/ApiError'
      required:
        - data
        - error
      additionalProperties: false
    GamCustomTargetingKeyEntry:
      type: object
      properties:
        name:
          type: string
        keyId:
          type: string
        displayName:
          type: string
      required:
        - name
        - keyId
        - displayName
      additionalProperties: false
    ApiError:
      description: Structured error object
      type: object
      properties:
        code:
          description: Machine-readable error code
          type: string
        message:
          description: Human-readable error message
          type: string
        field:
          description: Field path associated with the error
          type: string
        details:
          description: Additional error context
          type: object
          additionalProperties: {}
      required:
        - code
        - message
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key or access token

````