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

# Create (or get) a customer

> Get-or-create by email. Returns 201 for a new customer, 200 if one with that email already exists.



## OpenAPI

````yaml /v3-beta/api-reference/openapi.yaml post /v3/customers
openapi: 3.1.0
info:
  title: Suby.fi Merchant API
  version: 3.0.0-beta
  description: >
    The **v3** public merchant API for Suby.fi. RESTful (plural,
    resource-oriented

    endpoints under the `/v3` prefix). Authenticate every request

    with your secret API key in the `X-Suby-Api-Key` header.


    - `sk_live_…` keys operate in **production** (real funds).

    - `sk_sandbox_…` keys operate in a fully simulated **sandbox** (test cards,
      Base Sepolia crypto, no real money). The environment is derived from the
      key prefix.

    All monetary amounts are **integer cents** (except `priceCents` on some

    read shapes, which is a string) — token amounts are strings in the smallest

    unit (sats / lamports / wei). Fees are basis points.
  contact:
    email: dev@suby.fi
    url: https://suby.fi
servers:
  - url: https://api.beta.suby.fi
    description: Production + sandbox (environment selected by API key prefix)
security:
  - ApiKeyAuth: []
tags:
  - name: Products
    description: Manage your product catalog (one-time and recurring).
  - name: Checkout
    description: >-
      Hosted checkout — signed session tokens (`cs_…`) plus branding and
      appearance settings.
  - name: Payments
    description: >-
      Create, capture, void, and retrieve one-time & off-session payments (card,
      APM, and crypto).
  - name: Subscriptions
    description: Start and cancel recurring subscriptions.
  - name: Customers
    description: First-class customer records with billing address.
  - name: Payment Methods
    description: >-
      Save a payment method to a customer and manage saved instruments for
      off-session charges.
  - name: Webhook Endpoints
    description: Register outbound webhook destinations and rotate signing secrets.
  - name: Analytics
    description: Org-wide revenue analytics.
  - name: Health
    description: Unauthenticated liveness probe.
paths:
  /v3/customers:
    post:
      tags:
        - Customers
      summary: Create (or get) a customer
      description: >-
        Get-or-create by email. Returns 201 for a new customer, 200 if one with
        that email already exists.
      operationId: createCustomer
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - email
              description: >-
                Idempotent get-or-create keyed on `email` (per org +
                environment) — the same email always resolves to the same
                customer.
              properties:
                email:
                  type: string
                  format: email
                  maxLength: 320
                  description: Identity key. Required.
                firstName:
                  type: string
                  maxLength: 100
                  description: Optional; forwarded to the PSP on card charges.
                lastName:
                  type: string
                  maxLength: 100
                billingAddress:
                  $ref: '#/components/schemas/BillingAddress'
                  description: Optional; drives VAT country + pre-fills future charges.
                externalRef:
                  type: string
                  maxLength: 120
                  description: >-
                    Your business reference (CRM/customer id). Stored + echoed +
                    filterable via `?externalRef=`. Not unique.
                metadata:
                  $ref: '#/components/schemas/Metadata'
      responses:
        '200':
          description: Existing customer returned
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - properties:
                      data:
                        $ref: '#/components/schemas/Customer'
        '201':
          description: Customer created
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - properties:
                      data:
                        $ref: '#/components/schemas/Customer'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        Optional key (≤255 chars, e.g. a UUID v4) that makes this POST safe to
        retry: the first request executes and its response is cached for 24h; a
        retry with the SAME key replays that response instead of re-executing
        (no duplicate payment/subscription). A reused key with a different
        request → `422 IDEMPOTENCY_KEY_CONFLICT`; a retry while the first is
        still in flight → `409`. See the Idempotency guide.
      schema:
        type: string
        maxLength: 255
        example: 5f3b9c2e-1a4d-4f2b-9c31-7e2a1b6d8c04
  schemas:
    BillingAddress:
      type: object
      properties:
        line1:
          type: string
          maxLength: 200
          nullable: true
        line2:
          type: string
          maxLength: 200
          nullable: true
        city:
          type: string
          maxLength: 120
          nullable: true
        state:
          type: string
          maxLength: 120
          nullable: true
        postalCode:
          type: string
          maxLength: 40
          nullable: true
        country:
          type: string
          description: ISO 3166-1 alpha-2.
          pattern: ^[A-Z]{2}$
          nullable: true
    Metadata:
      type: object
      additionalProperties:
        type: string
        nullable: true
      description: |
        Key-value pairs. ≤50 keys, keys ≤40 chars, values are
        strings ≤500 chars (or `null` to clear). Nested structures must be
        JSON-stringified into a single string value.
    SuccessEnvelope:
      type: object
      required:
        - success
        - data
      properties:
        success:
          type: boolean
          example: true
        message:
          type: string
        data:
          description: Endpoint-specific payload.
    Customer:
      type: object
      properties:
        id:
          type: string
          example: cus_abc123
        organizationId:
          type: string
        email:
          type: string
          format: email
        firstName:
          type: string
          nullable: true
        lastName:
          type: string
          nullable: true
        billingLine1:
          type: string
          nullable: true
        billingLine2:
          type: string
          nullable: true
        billingCity:
          type: string
          nullable: true
        billingState:
          type: string
          nullable: true
        billingPostalCode:
          type: string
          nullable: true
        billingCountry:
          type: string
          nullable: true
        businessName:
          type: string
          nullable: true
          description: Set when the buyer purchased as a business.
        taxId:
          type: string
          nullable: true
          description: Buyer VAT / fiscal number.
        externalRef:
          type: string
          nullable: true
          description: >-
            Merchant business reference set at create/update. Filter with
            `?externalRef=`.
        taxRateBps:
          type: integer
          nullable: true
          description: >-
            VAT rate (bps) for the billing country under the merchant's MoR
            mode; null for non-MoR merchants.
        customerAccountEVM:
          type: string
          nullable: true
        customerAccountSOL:
          type: string
          nullable: true
        customerAccountBTC:
          type: string
          nullable: true
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    Error:
      type: object
      required:
        - success
        - error
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
          description: Machine-readable error code.
          example: NOT_FOUND
        message:
          type: string
          example: Resource not found
        data:
          description: Optional error detail.
    ValidationErrorEnvelope:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          properties:
            data:
              type: object
              properties:
                fieldErrors:
                  type: array
                  items:
                    type: object
                    properties:
                      field:
                        type: string
                      message:
                        type: string
  responses:
    Unauthorized:
      description: Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            success: false
            error: UNAUTHORIZED
            message: Invalid or missing API key
    ValidationError:
      description: Request failed schema validation
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationErrorEnvelope'
          example:
            success: false
            error: VALIDATION_ERROR
            message: Validation failed
            data:
              fieldErrors:
                - field: method
                  message: method is a required field
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Suby-Api-Key
      description: Secret API key. `sk_live_…` (production) or `sk_sandbox_…` (sandbox).

````