> ## 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 DKIM Key Status

> Update fields of an existing DKIM key pair for the specified domain and selector, for the current customer.
Currently, only the status field can be updated.
revoked: Indicates that the key is compromised and should not be used.
retired: Indicates that the key has been rotated and is no longer in use.
rotated: Indicates that the key is going through the rotation process. Only active key pairs can be
updated to this status, and no new key pair is created. The rotated key can be used to sign emails for 3 days after
the status update, and will automatically change to 'retired' 2 weeks after update. For a smooth key transition,
it is recommended to create and publish a new key pair before signing is disabled for the rotated key.




## OpenAPI

````yaml /email-api/api-reference/openapi.yaml patch /domains/{domain}/dkim-keys/{selector}
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.4.0
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:
  /domains/{domain}/dkim-keys/{selector}:
    patch:
      tags:
        - DKIM
      summary: Update DKIM Key Status
      description: >
        Update fields of an existing DKIM key pair for the specified domain and
        selector, for the current customer.

        Currently, only the status field can be updated.

        revoked: Indicates that the key is compromised and should not be used.

        retired: Indicates that the key has been rotated and is no longer in
        use.

        rotated: Indicates that the key is going through the rotation process.
        Only active key pairs can be

        updated to this status, and no new key pair is created. The rotated key
        can be used to sign emails for 3 days after

        the status update, and will automatically change to 'retired' 2 weeks
        after update. For a smooth key transition,

        it is recommended to create and publish a new key pair before signing is
        disabled for the rotated key.
      parameters:
        - in: path
          name: domain
          required: true
          schema:
            type: string
        - in: path
          name: selector
          required: true
          schema:
            maxLength: 63
            minLength: 1
            type: string
        - in: header
          name: X-Api-Key
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DKIMKeyPairUpdateRequest'
        required: true
      responses:
        '204':
          description: Key pair status updated successfully
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Status not supported
        '404':
          description: >
            Specified key pair not found, or no active key for rotation

            This may also occur if the DKIM domain or selector path parameter is
            missing.
        '500':
          description: Internal Server Error
      x-codeSamples:
        - label: Node.js
          lang: javascript
          source: >-
            import { MailChannels } from "mailchannels-sdk";


            const { MAILCHANNELS_API_KEY, DOMAIN, SELECTOR } = process.env;

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

            if (!DOMAIN) throw new Error("Set DOMAIN (the sending domain, e.g.
            example.com)");

            if (!SELECTOR) throw new Error("Set SELECTOR (the DKIM key selector
            to update)");


            const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);


            const { success, error } = await
            mailchannels.domains.dkim.updateStatus(DOMAIN, {
              selector: SELECTOR,
              status: "retired",
            });


            if (!success) {
              console.error("Update DKIM key status failed:", error);
              process.exit(1);
            }

            console.log({ success });
        - 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")

            domain = os.environ.get("DOMAIN")

            selector = os.environ.get("SELECTOR")

            if not domain:
                sys.exit("Set DOMAIN (the sending domain, e.g. example.com)")
            if not selector:
                sys.exit("Set SELECTOR (the DKIM key selector to update)")

            response = mailchannels.Dkim.update_status(domain, selector,
            status="retired")


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


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


            use MailChannels\Client;


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

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

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


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


            $response = $client->dkim->updateStatus($domain, $selector,
            'retired');


            echo "HTTP Status: " . $response->statusCode . "\n";
components:
  schemas:
    DKIMKeyPairUpdateRequest:
      properties:
        status:
          description: |
            New status of the DKIM key pair
          enum:
            - revoked
            - retired
            - rotated
          type: string
      required:
        - status
      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

````