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

# Attach external payment method

> Attaches an external payment method (from Stripe or other provider) to a customer. **Connector Auto-Detection:**
- If 'connector' is not provided, the system will automatically detect the connector by querying resource mappings
- If exactly one connector mapping exists for the customer, it will be used automatically
- If multiple connector mappings exist, you must explicitly specify which connector to use
- If no connector mappings exist, an error will be returned



## OpenAPI

````yaml /openAPI/openapi-20240301.json post /customers/{customer_id}/payment_methods/attach
openapi: 3.1.0
info:
  title: zenskar
  version: 2.0.0
servers:
  - url: https://api.zenskar.com
security:
  - ApiTokenAuth: []
    OrganisationAuth: []
paths:
  /customers/{customer_id}/payment_methods/attach:
    post:
      tags:
        - Customers
      summary: Attach external payment method
      description: >-
        Attaches an external payment method (from Stripe or other provider) to a
        customer. **Connector Auto-Detection:**

        - If 'connector' is not provided, the system will automatically detect
        the connector by querying resource mappings

        - If exactly one connector mapping exists for the customer, it will be
        used automatically

        - If multiple connector mappings exist, you must explicitly specify
        which connector to use

        - If no connector mappings exist, an error will be returned
      operationId: Attach-external-payment-method
      parameters:
        - name: customer_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Customer Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AttachPaymentMethodRequestSchema'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AttachPaymentMethodResponseSchema'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    AttachPaymentMethodRequestSchema:
      properties:
        payment_method_id:
          type: string
          minLength: 1
          title: Payment Method Id
          description: Payment method ID from external provider (e.g., Stripe pm_xxx)
        connector:
          anyOf:
            - $ref: '#/components/schemas/app__customer__schema__Connector'
            - type: 'null'
          description: >-
            Payment provider connector configuration (e.g., {'name': 'stripe'}).
            If not provided, will auto-detect from resource mappings.
        set_as_default:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Set As Default
          description: Whether to set this payment method as default for the customer
      type: object
      required:
        - payment_method_id
      title: AttachPaymentMethodRequestSchema
      description: Request schema for attaching external payment method to customer
    AttachPaymentMethodResponseSchema:
      properties:
        customer_id:
          type: string
          title: Customer Id
          description: Customer ID
        payment_method_id:
          type: string
          title: Payment Method Id
          description: Attached payment method ID
        external_id:
          type: string
          title: External Id
          description: External customer ID (e.g., Stripe customer ID)
        set_as_default:
          type: boolean
          title: Set As Default
          description: Whether payment method was set as default
        raw_data:
          additionalProperties: true
          type: object
          title: Raw Data
          description: Raw PaymentMethod object from provider
      type: object
      required:
        - customer_id
        - payment_method_id
        - external_id
        - set_as_default
        - raw_data
      title: AttachPaymentMethodResponseSchema
      description: Response schema for payment method attachment operation
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    app__customer__schema__Connector:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: >-
            Name of the external connector or integration (e.g., 'stripe',
            'salesforce')
        reference_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Reference Id
          description: Customer ID in the external system (e.g., Stripe customer ID)
      type: object
      title: Connector
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    ApiTokenAuth:
      type: apiKey
      in: header
      name: x-api-key
      x-default: <your-api-key>
    OrganisationAuth:
      type: apiKey
      in: header
      name: organisation
      x-default: <your-organisation-id>

````