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

# Set default payment method

> Sets or clears the customer's default payment method. Pass `null` for `default_payment_method` to clear it. The method must already be attached to the customer.



## OpenAPI

````yaml /openapi/customers.yaml post /customers/{id}/default_payment_method
openapi: 3.0.3
info:
  title: Ionic Customers API
  version: '2026-05-01'
  description: |
    Customer profiles — the anchor for payment methods, invoices, and
    subscriptions.

    A customer (`cus_…`) represents a single payer stored under your merchant
    account. It holds contact information (email, name, phone), optional billing
    and shipping addresses, and a link to a default payment method. Invoices and
    subscriptions reference customers by id; payment methods are attached to
    customers and become available for off-session charges.

    All timestamps are Unix epoch seconds. Identifiers are opaque, prefixed
    strings.

    Authentication uses a merchant secret key (`sk_…`) as a bearer token.
    Read endpoints require the `customers:read` permission; write endpoints
    require `customers:write`. The mode of the key (test or live) scopes which
    customers it can see and mutate.

    Customers support soft-delete: a deleted customer has `deleted: true` and
    cannot be modified until restored. Write endpoints that target a deleted
    customer return `422`. To undo a deletion, call the restore endpoint.

    Errors are returned as `{ "error": { "code": "...", "message": "..." } }`.
servers:
  - url: '{baseUrl}/v1'
    variables:
      baseUrl:
        default: https://api.ionicfi.com
        description: API base URL for your environment.
security:
  - secretKey: []
tags:
  - name: Customers
    description: Create, retrieve, update, and manage customer profiles.
paths:
  /customers/{id}/default_payment_method:
    parameters:
      - $ref: '#/components/parameters/CustomerId'
      - $ref: '#/components/parameters/IonicAccount'
    post:
      tags:
        - Customers
      summary: Set default payment method
      description: >-
        Sets or clears the customer's default payment method. Pass `null` for
        `default_payment_method` to clear it. The method must already be
        attached to the customer.
      operationId: customers_set_default_payment_method
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SetDefaultPaymentMethodRequest'
      responses:
        '200':
          description: The updated customer.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Customer'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/CustomerNotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - secretKey:
            - customers:write
components:
  parameters:
    CustomerId:
      name: id
      in: path
      required: true
      description: The customer id (`cus_…`).
      schema:
        type: string
    IonicAccount:
      name: Ionic-Account
      in: header
      required: false
      description: |
        Merchant ID when an authorized Platform acts for a connected Merchant.
        Omit when authenticating directly as that Merchant.
      schema:
        type: string
        pattern: ^mer_[0-9A-Za-z]{14}$
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        A unique key that makes retries safe: the same key with the same request
        body returns the original response instead of repeating the operation.
      schema:
        type: string
        maxLength: 255
  schemas:
    SetDefaultPaymentMethodRequest:
      type: object
      properties:
        default_payment_method:
          type: string
          nullable: true
          description: Payment method id (`pm_…`). Pass `null` to clear the default.
    Customer:
      type: object
      required:
        - billing_address
        - created_at
        - creation_source
        - deleted
        - email
        - first_name
        - id
        - last_name
        - livemode
        - merchant_id
        - metadata
        - object
        - payment_settings
        - phone
        - shipping
        - test_clock
        - updated_at
      properties:
        id:
          type: string
          description: Unique customer identifier (`cus_…`).
        object:
          type: string
          enum:
            - customer
        merchant_id:
          type: string
        livemode:
          type: boolean
          description: >-
            Whether this customer was created with a live (`true`) or test
            (`false`) key.
        test_clock:
          type: string
          nullable: true
          description: >-
            The immutable logical billing clock attached at creation; null when
            this customer uses wall-clock time.
        email:
          type: string
        first_name:
          type: string
          description: Empty string when not set.
        last_name:
          type: string
          description: Empty string when not set.
        phone:
          type: string
          description: Empty string when not set.
        billing_address:
          allOf:
            - $ref: '#/components/schemas/Address'
          nullable: true
          description: Billing address; null when not set.
        shipping:
          allOf:
            - $ref: '#/components/schemas/ShippingDetails'
          nullable: true
          description: Shipping details; null when not set.
        creation_source:
          type: string
          enum:
            - api
            - checkout
            - import
            - dashboard
            - platform
          description: How the customer was created (for example `api`).
        payment_settings:
          $ref: '#/components/schemas/PaymentSettings'
        metadata:
          type: object
          additionalProperties:
            type: string
        deleted:
          type: boolean
          description: True when the customer has been soft-deleted.
        created_at:
          type: integer
          description: Unix epoch seconds.
        updated_at:
          type: integer
    Address:
      type: object
      required:
        - city
        - country
        - line1
        - postal_code
        - state
      properties:
        line1:
          type: string
        line2:
          type: string
          description: Second address line; absent when not set.
        city:
          type: string
        state:
          type: string
        postal_code:
          type: string
        country:
          type: string
          description: ISO 3166-1 alpha-2 country code.
    ShippingDetails:
      type: object
      required:
        - address
        - name
        - phone
      properties:
        name:
          type: string
          description: Recipient name.
        phone:
          type: string
          description: Recipient phone number.
        address:
          $ref: '#/components/schemas/Address'
    PaymentSettings:
      type: object
      description: Payment configuration stored for the customer.
      properties:
        default_payment_method:
          type: string
          description: The default payment method id (`pm_…`); absent when none is set.
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: A stable, machine-readable error code.
            message:
              type: string
  responses:
    BadRequest:
      description: The request was malformed or failed validation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: INVALID_REQUEST
              message: invalid request body
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: The key lacks the required permission, or the merchant is not active.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    CustomerNotFound:
      description: No customer with that id is visible to this key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: CUSTOMER_NOT_FOUND
              message: customer not found
    RateLimited:
      description: Too many requests. Honour the `Retry-After` header before retrying.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalError:
      description: |
        The API could not return a successful response. For a mutating request,
        retrieve the resource before retrying because the operation may have
        completed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      description: 'A merchant secret key (`sk_…`) sent as `Authorization: Bearer <key>`.'

````