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

# Update Custom Tracking Domain

> Update an existing custom tracking domain by its hostname and scope.
Supports updating the custom tracking domain's name or toggling its active status.




## OpenAPI

````yaml /email-api/api-reference/openapi.yaml patch /custom-tracking-domains/{hostname}/{scope}
openapi: 3.0.0
info:
  contact:
    email: support@mailchannels.com
    name: MailChannels Corporation
  description: >
    This is the API reference for Email API. Here, you'll find more detailed
    information on every endpoint, including parameters, response formats, and
    error codes.
  title: Email API
  version: 1.7.1
servers:
  - url: https://api.mailchannels.net/tx/v1
security: []
tags:
  - name: Send
  - name: DKIM
  - name: Metrics
  - name: Sub-accounts
  - name: Suppression
  - name: Webhooks
  - name: Usage
  - name: Custom Tracking
paths:
  /custom-tracking-domains/{hostname}/{scope}:
    patch:
      tags:
        - Custom Tracking
      summary: Update Custom Tracking Domain
      description: >
        Update an existing custom tracking domain by its hostname and scope.

        Supports updating the custom tracking domain's name or toggling its
        active status.
      parameters:
        - in: path
          name: hostname
          required: true
          schema:
            type: string
        - in: path
          name: scope
          required: true
          schema:
            enum:
              - click
              - open
              - unsubscribe
            type: string
        - in: header
          name: X-Api-Key
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchCustomTrackingDomainRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomTrackingDomain'
          description: Custom tracking domain updated
        '202':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DnsSetupRequired'
          description: >-
            Re-activation requires DNS verification — add the TXT record and
            CNAME record described in the response body, then retry
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Invalid request body
        '403':
          description: No permission to activate this domain
        '404':
          description: Domain not found
        '409':
          description: Name already used by another domain
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DnsSetupRequired'
          description: >
            DNS verification incomplete. Either the TXT ownership record has not
            propagated yet

            or the hostname CNAME does not point to the required target.

            Check the `instructions` field and retry once both records are in
            place.
        '500':
          description: Internal server error
      x-codeSamples:
        - label: Node.js
          lang: javascript
          source: >-
            import { MailChannels } from "mailchannels-sdk";


            const { MAILCHANNELS_API_KEY, TRACKING_HOSTNAME } = process.env;

            if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY
            before running");

            if (!TRACKING_HOSTNAME) throw new Error("Set TRACKING_HOSTNAME (e.g.
            click.example.com)");


            const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);


            // Disable a custom tracking domain (identified by hostname and
            scope) without deleting it.

            const { data, error } = await
            mailchannels.domains.customTracking.update(TRACKING_HOSTNAME,
            "click", {
              status: "disabled",
            });


            if (error) {
              console.error("Update custom tracking domain failed:", error);
              process.exit(1);
            }

            console.log(data);
        - label: Python
          lang: python
          source: >-
            import os

            import sys


            import mailchannels


            if not os.environ.get("MAILCHANNELS_API_KEY"):
                sys.exit("Set MAILCHANNELS_API_KEY before running")

            hostname = os.environ.get("TRACKING_HOSTNAME")

            if not hostname:
                sys.exit("Set TRACKING_HOSTNAME (e.g. click.example.com)")

            # Disable a custom tracking domain (identified by hostname and
            scope) without deleting it.

            response = mailchannels.CustomTrackingDomains.update(hostname,
            "click", status="disabled")


            print(response)
        - label: PHP
          lang: php
          source: >-
            <?php


            require_once __DIR__ . '/vendor/autoload.php';


            use MailChannels\Client;

            use MailChannels\Enum\CustomTrackingScope;

            use MailChannels\Enum\CustomTrackingStatus;


            $api_key  = getenv('MAILCHANNELS_API_KEY') or exit("Error:
            MAILCHANNELS_API_KEY is not set\n");

            $hostname = getenv('TRACKING_HOSTNAME') or exit("Error:
            TRACKING_HOSTNAME is not set\n");


            $client = new Client(apiKey: $api_key);


            // Disable a custom tracking domain (identified by hostname and
            scope) without deleting it.

            $response = $client->customTrackingDomains->update(
                $hostname,
                CustomTrackingScope::Click,
                status: CustomTrackingStatus::Disabled,
            );


            print_r($response->toArray());
components:
  schemas:
    PatchCustomTrackingDomainRequest:
      properties:
        name:
          description: New label for this custom tracking domain
          maxLength: 64
          pattern: ^[a-z0-9-]+$
          type: string
        status:
          description: New status; active ↔ disabled
          enum:
            - active
            - disabled
          type: string
      type: object
    CustomTrackingDomain:
      properties:
        created_at:
          description: ISO 8601 timestamp when the domain was registered
          format: date-time
          type: string
        hostname:
          description: The registered domain hostname
          type: string
        name:
          description: The label for this custom tracking domain
          type: string
        scope:
          description: The event type this domain handles
          enum:
            - click
            - open
            - unsubscribe
          type: string
        status:
          description: Current status of the custom tracking domain
          enum:
            - active
            - disabled
          type: string
      required:
        - name
        - hostname
        - scope
        - status
        - created_at
      type: object
    DnsSetupRequired:
      properties:
        instructions:
          description: >-
            Human-readable guidance for the DNS records that must be in place
            before retrying.
          type: string
        token:
          description: >-
            UUID v4 nonce; also the TXT record value to set. Present only when
            TXT ownership verification is pending.
          example: 550e8400-e29b-41d4-a716-446655440000
          type: string
        txt_record_name:
          description: >-
            Fully-qualified DNS TXT record name to add. Present only when TXT
            ownership verification is pending.
          example: _mailchannels-verify.click.example.com
          type: string
        txt_record_value:
          description: >-
            Value for the DNS TXT record (same as token). Present only when TXT
            ownership verification is pending.
          example: 550e8400-e29b-41d4-a716-446655440000
          type: string
      type: object
    ErrorResponse:
      properties:
        errors:
          description: >
            This is an array error objects that provide machine and human
            readable descriptions of the errors.
          items:
            type: string
          type: array
      type: object

````