---
openapi: 3.0.3
info:
  title: Braze REST API – Set primary SDK Authentication key
  description: |
    ## Prerequisites

    To use this endpoint, you'll need an [API key]({{site.baseurl}}/api/basics#rest-api-key-permissions) with the `sdk_authentication.primary` permission.

    ## Rate limit

    This endpoint has a rate limit of 100 requests per day per workspace, shared between all SDK Authentication endpoints and `GET /app_group/apps`. Requests count toward the limit even when they fail validation. For more information, see [API rate limits]({{site.baseurl}}/api/api_limits/).
  version: 1.0.0
  contact:
    name: Braze Support
    url: https://www.braze.com/docs/braze_support/
  license:
    name: Braze Documentation
    url: https://www.braze.com/docs/api/home/
servers:
  - url: https://rest.iad-01.braze.com
    description: US-01
  - url: https://rest.iad-02.braze.com
    description: US-02
  - url: https://rest.iad-03.braze.com
    description: US-03
  - url: https://rest.iad-04.braze.com
    description: US-04
  - url: https://rest.iad-05.braze.com
    description: US-05
  - url: https://rest.iad-06.braze.com
    description: US-06
  - url: https://rest.iad-07.braze.com
    description: US-07
  - url: https://rest.iad-08.braze.com
    description: US-08
  - url: https://rest.us-10.braze.com
    description: US-10
  - url: https://rest.fra-01.braze.eu
    description: EU-01
  - url: https://rest.fra-02.braze.eu
    description: EU-02
  - url: https://rest.au-01.braze.com
    description: AU-01
  - url: https://rest.id-01.braze.com
    description: ID-01
  - url: https://rest.jp-01.braze.com
    description: JP-01
  - url: https://rest.kr-01.braze.com
    description: KR-01
security:
- BearerAuth: []
paths:
  "/app_group/sdk_authentication/primary":
    put:
      summary: Set primary SDK Authentication key
      operationId: put_app_group_sdk_authentication_primary_put_primary_sdk_authentication_key
      description: |
        ## Validation rules

        This endpoint has the following validation rules:

        - The `key_id` must be a valid SDK Authentication key ID.
        - The `app_id` must be a valid app API identifier.
        - The SDK Authentication key must exist for the specified app.
      requestBody:
        required: true
        description: The following sample request shows an example of how to set primary SDK Authentication key.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SetPrimarySdkAuthenticationKeyRequest'
            examples:
              example_request:
                summary: Set the primary SDK Authentication key
                value:
                  app_id: 01234567-89ab-cdef-0123-456789abcdef
                  key_id: 65a1f0c2e4b0a1b2c3d4e5f6
              request_body_template:
                summary: Request body template
                value:
                  app_id: App API identifier
                  key_id: key id
      responses:
        "200":
          description: |
            The request succeeded and the primary SDK Authentication key was set. No action needed.

            The following sample response shows an example of the response returned when you set primary SDK Authentication key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PrimarySdkAuthenticationKeyResponse'
              examples:
                success:
                  summary: All SDK Authentication keys, primary first
                  value:
                    keys:
                      - id: 65a1f0c2e4b0a1b2c3d4e5f6
                        rsa_public_key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvvD+fgA0YuCUd/v35htn...\n-----END PUBLIC KEY-----"
                        description: SDK Authentication Key for iOS App
                        is_primary: true
                      - id: 65a1f0c2e4b0a1b2c3d4e5f7
                        rsa_public_key: "-----BEGIN PUBLIC KEY-----\nqWGfHOAiIwVzC/bTxwQZQQVzm/3ktgdNXRUDm5aIwVzCtxbNm5aIxOAiIwVzVHOA...\n-----END PUBLIC KEY-----"
                        description: SDK Authentication Key for Android App
                        is_primary: false
        "400":
          description: |
            Bad request. To resolve it:

            - **The `app_id` is missing or isn't a valid app API identifier for this workspace:** Pass a valid `app_id` from the [API Keys page]({{site.baseurl}}/user_guide/administer/global/workspace_settings/apis_and_identifiers/).
            - **The `key_id` is missing:** Include the `key_id` of the SDK Authentication key.
            - **The `key_id` doesn't match a key for this app:** Pass a `key_id` returned by the [List SDK Authentication keys endpoint]({{site.baseurl}}/api/endpoints/sdk_authentication/get_sdk_authentication_keys/).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_app_id:
                  summary: Missing or invalid app_id
                  value:
                    message: 'Missing or invalid required parameter: app_id'
                missing_key_id:
                  summary: Missing key_id
                  value:
                    message: 'Missing required parameter: key_id'
                invalid_key_id:
                  summary: key_id doesn't match a key for this app
                  value:
                    message: Invalid key_id
        "401":
          description: |
            Unauthorized. The REST API key is missing, malformed, or sent to the wrong REST endpoint. Send the key as `Authorization: Bearer YOUR_REST_API_KEY` to the correct [REST endpoint]({{site.baseurl}}/api/basics/#endpoints). For more causes, see [Errors and responses]({{site.baseurl}}/api/errors/#fatal-errors).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_api_key:
                  summary: Invalid API key
                  value:
                    message: 'Invalid API key: YOUR_REST_API_KEY'
        "403":
          description: Access denied. The REST API key doesn't have the required permission. Use a REST API key that has the `sdk_authentication.primary` permission.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                access_denied:
                  summary: Missing permission
                  value:
                    message: Access Denied
        "429":
          description: |
            Rate limited. You exceeded the limit of 100 requests per day shared between the SDK Authentication endpoints and `GET /app_group/apps`. Wait for the limit to reset before retrying. See [API rate limits]({{site.baseurl}}/api/api_limits/).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                rate_limited:
                  summary: Daily rate limit exceeded
                  value:
                    message: You have exceeded your limit of 100 requests per day. Please contact your account executive to increase your limit. If you do not have their info, you may contact Braze directly at https://www.braze.com/contact/.
        5XX:
          description: |
            Internal server error. An unexpected error occurred on the Braze server. Retry with exponential backoff. If the error persists, contact [Support]({{site.baseurl}}/braze_support/).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: REST API key
      description: |
        REST API keys are created in the Braze dashboard at **Settings → APIs and
        Identifiers → API Keys**. The key must include the `sdk_authentication.primary` permission.
        Pass the key as `Authorization: Bearer YOUR_REST_API_KEY`.
  schemas:
    SetPrimarySdkAuthenticationKeyRequest:
      title: Set primary SDK Authentication key request
      type: object
      required: [app_id, key_id]
      properties:
        app_id:
          type: string
          description: The app API identifier.
          example: 01234567-89ab-cdef-0123-456789abcdef
        key_id:
          type: string
          description: The ID of the SDK Authentication key to mark as primary, a 24-character hexadecimal string.
          example: 65a1f0c2e4b0a1b2c3d4e5f6
    SdkAuthenticationKey:
      title: SDK Authentication key
      type: object
      properties:
        id:
          type: string
          description: The ID of the SDK Authentication key, a 24-character hexadecimal string.
          example: 65a1f0c2e4b0a1b2c3d4e5f6
        rsa_public_key:
          type: string
          description: The RSA public key string.
          example: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvvD+fgA0YuCUd/v35htn...\n-----END PUBLIC KEY-----"
        description:
          type: string
          nullable: true
          description: Description of the SDK Authentication key. Keys created in the dashboard can have no description, in which case this is `null`.
          example: SDK Authentication Key for iOS App
        is_primary:
          type: boolean
          description: Whether this key is the primary SDK Authentication key.
          example: true
    PrimarySdkAuthenticationKeyResponse:
      title: Set primary SDK Authentication key response
      type: object
      properties:
        keys:
          type: array
          description: Array of all SDK Authentication key objects.
          items:
            $ref: '#/components/schemas/SdkAuthenticationKey'
        message:
          type: string
          example: success
    ErrorResponse:
      title: Error
      type: object
      properties:
        message:
          type: string
          description: The error message describing why the request failed.
