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

# Update a tracking pixel

> Rename a tracking pixel or replace its provider or custom-code configuration.

`PATCH /v1/tracking-pixel/{pixel_id}` updates one tracking pixel in the API
key's workspace. It requires **Tracking pixels: Write**
(`tracking_pixels.update`).

The API playground provides three request variants: **Rename only**,
**Provider configuration**, and **Custom code configuration**.

<Note>
  Select **Custom code configuration** above the request fields when editing
  custom code. `custom` is not a provider dropdown option.
</Note>

## Rename without changing configuration

Send only `name` to preserve the current type and all compatible configuration.

```bash theme={null}
curl --request PATCH \
  --url https://biq.li/api/v1/tracking-pixel/biq_pxl_01M00000000000000000000000 \
  --header 'Authorization: Bearer biqli_your_workspace_api_key' \
  --header 'Content-Type: application/json' \
  --data '{"name":"Primary acquisition pixel"}'
```

## Update a provider pixel

When changing provider configuration, include `type` and `pixel_id` together.
You may also include `name` in the same request.

```json theme={null}
{
  "type": "google-analytics",
  "pixel_id": "G-ABC1234567"
}
```

The request may keep the current provider type or select another supported
provider. Do not include `head_code` or `body_code`. After a successful update,
both custom-code fields are `null`.

## Update custom code

Include `type: "custom"` whenever changing `head_code` or `body_code`.

```json theme={null}
{
  "type": "custom",
  "head_code": "<script src=\"https://analytics.example.com/v2.js\"></script>"
}
```

Omitted custom-code fields keep their existing values when the pixel is already
custom. Send `null` to clear one code field. The resulting configuration must
still have a non-empty `head_code` or `body_code`.

```json theme={null}
{
  "type": "custom",
  "head_code": null,
  "body_code": "<script>window.exampleAnalytics.start()</script>"
}
```

## Change between provider and custom

Type changes are atomic and remove fields that do not belong to the new type.

* Provider to custom: send `type: "custom"` and at least one code field. Biqli
  clears the old `pixel_id`.
* Custom to provider: send the new provider `type` and `pixel_id`. Biqli clears
  both custom-code fields.
* Provider to provider: send the new `type` and its matching `pixel_id`.

This prevents old custom JavaScript from remaining attached to a provider pixel
and prevents a stale provider ID from remaining on a custom configuration.

## Validation behavior

The endpoint returns `422 validation_error` when:

* `pixel_id` is sent without `type`.
* `head_code` or `body_code` is sent without `type: "custom"`.
* A provider request includes either custom-code field.
* A custom request includes `pixel_id`.
* A provider request does not include a non-empty `pixel_id`.
* The resulting custom configuration has no non-empty code field.
* The body is empty or contains an unknown field.

A duplicate name returns `409 pixel_name_taken`. Success returns `200 OK` with
the complete updated resource.

## Shared API behavior

Authentication is workspace-scoped; see
[Authentication](/docs/api-reference/authentication). Errors use the standard
envelope and request IDs described in [Errors](/docs/api-reference/errors), and
requests are subject to [Rate limits](/docs/api-reference/rate-limits).


## OpenAPI

````yaml PATCH /v1/tracking-pixel/{pixel}
openapi: 3.1.0
info:
  title: Biqli API
  version: 1.0.0
  description: Workspace-scoped REST API for Biqli.
servers:
  - url: https://biq.li/api
security:
  - bearerAuth: []
paths:
  /v1/tracking-pixel/{pixel}:
    parameters:
      - $ref: '#/components/parameters/PixelId'
    patch:
      tags:
        - Tracking pixels
      summary: Update a tracking pixel
      description: Requires tracking_pixels.update.
      operationId: pixel.update
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PixelPatch'
      responses:
        '200':
          description: Updated pixel.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PixelResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    PixelId:
      name: pixel
      in: path
      required: true
      schema:
        type: string
        pattern: ^biq_pxl_[0-9A-HJKMNP-TV-Z]{26}$
  schemas:
    PixelPatch:
      oneOf:
        - title: Rename only
          type: object
          additionalProperties: false
          required:
            - name
          properties:
            name:
              type: string
              minLength: 3
              maxLength: 80
        - title: Provider configuration
          type: object
          additionalProperties: false
          required:
            - type
            - pixel_id
          properties:
            name:
              type: string
              minLength: 3
              maxLength: 80
            type:
              type: string
              enum:
                - facebook
                - twitter
                - google-tag-manager
                - google-analytics
                - adwords
                - bing
                - pinterest
                - linkedin
                - quora
                - adroll
                - nexus-segment
            pixel_id:
              type: string
              minLength: 1
              maxLength: 200
              description: >-
                Include type and pixel_id together when changing provider
                configuration.
        - title: Custom code configuration
          type: object
          additionalProperties: false
          required:
            - type
          minProperties: 2
          description: Include type custom and at least one custom code field.
          properties:
            type:
              type: string
              const: custom
              default: custom
              x-default: custom
            head_code:
              type:
                - string
                - 'null'
              maxLength: 100000
              description: >-
                Set to null to clear it, provided the resulting custom pixel
                retains head_code or body_code.
            body_code:
              type:
                - string
                - 'null'
              maxLength: 100000
              description: >-
                Set to null to clear it, provided the resulting custom pixel
                retains head_code or body_code.
    PixelResponse:
      type: object
      required:
        - pixel
        - status
      properties:
        pixel:
          $ref: '#/components/schemas/Pixel'
        status:
          type: string
          const: success
    Pixel:
      type: object
      additionalProperties: false
      required:
        - id
        - name
        - type
        - pixel_id
        - head_code
        - body_code
        - links_count
      properties:
        id:
          type: string
          pattern: ^biq_pxl_[0-9A-HJKMNP-TV-Z]{26}$
        name:
          type: string
        type:
          type: string
          enum:
            - facebook
            - twitter
            - google-tag-manager
            - google-analytics
            - adwords
            - bing
            - pinterest
            - linkedin
            - quora
            - adroll
            - nexus-segment
            - custom
        pixel_id:
          type:
            - string
            - 'null'
          description: Provider identifier, or null for custom pixels.
        head_code:
          type:
            - string
            - 'null'
          description: Custom head code, or null for provider pixels.
        body_code:
          type:
            - string
            - 'null'
          description: Custom body code, or null for provider pixels.
        links_count:
          type: integer
          minimum: 0
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
    ApiError:
      type: object
      required:
        - error
        - request_id
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              enum:
                - invalid_token
                - insufficient_scope
                - upgrade_required
                - quota_exceeded
                - resource_not_found
                - domain_taken
                - alias_taken
                - external_id_taken
                - folder_name_taken
                - tag_name_taken
                - pixel_name_taken
                - biolink_name_taken
                - method_not_allowed
                - url_blocked
                - dns_verification_failed
                - validation_error
                - rate_limit_exceeded
                - internal_server_error
            message:
              type: string
            details:
              type: object
              additionalProperties: true
        request_id:
          type: string
          description: Request identifier to include when contacting support.
  responses:
    Unauthorized:
      $ref: '#/components/responses/ApiErrorResponse'
      description: The workspace API key is missing, invalid, or revoked.
    Forbidden:
      $ref: '#/components/responses/ApiErrorResponse'
      description: >-
        The key lacks a required scope, the workspace must upgrade, or its quota
        is exhausted.
    NotFound:
      $ref: '#/components/responses/ApiErrorResponse'
      description: >-
        The requested resource or referenced public ID is unavailable in the
        key's workspace.
    Conflict:
      $ref: '#/components/responses/ApiErrorResponse'
      description: >-
        A unique alias, external ID, custom domain, or workspace resource name
        is already in use.
    UnprocessableEntity:
      $ref: '#/components/responses/ApiErrorResponse'
      description: >-
        The payload is invalid, a destination was blocked, or domain DNS
        verification is not ready.
    RateLimited:
      description: The workspace exceeded its plan's API rate limit.
      headers:
        RateLimit-Policy:
          description: Current IETF HTTPAPI quota policy as a structured field.
          schema:
            type: string
            example: '"workspace-api";q=1000;w=60'
        RateLimit:
          description: Current IETF HTTPAPI service limit as a structured field.
          schema:
            type: string
            example: '"workspace-api";r=0;t=17'
        Retry-After:
          description: Seconds to wait before retrying the request.
          schema:
            type: integer
            minimum: 0
            example: 17
        X-RateLimit-Limit:
          description: Legacy maximum request count for the current window.
          schema:
            type: integer
            minimum: 1
            example: 1000
        X-RateLimit-Remaining:
          description: Legacy remaining request count.
          schema:
            type: integer
            minimum: 0
            example: 0
        X-RateLimit-Reset:
          description: Legacy reset time as a UTC Unix timestamp.
          schema:
            type: integer
            format: int64
            example: 1788126519
        X-Biq-Request-Id:
          description: Request identifier for support and tracing.
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    InternalError:
      $ref: '#/components/responses/ApiErrorResponse'
      description: The request failed unexpectedly.
    ApiErrorResponse:
      description: API error.
      headers:
        X-Biq-Request-Id:
          description: Request identifier for support and tracing.
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Workspace API key
      description: A workspace API key beginning with biqli_.

````