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

# Create Customer

> Create-or-update ("upsert") a customer, keyed on `email`, within the config's payment-provider account. Searches for an existing customer by email; if found, updates the most recently created match; otherwise creates a new customer. Idempotent on email.



## OpenAPI

````yaml /openapi.json post /billing-customers
openapi: 3.1.0
info:
  title: OpenLoop API
  version: 0.1.0
  description: >-
    Unified reference for the OpenLoop Patient (clinical) and Payments & Revenue
    APIs.
servers:
  - url: https://api.openloophealth.com/v0.1
    description: Production partner edge
  - url: https://api-staging.openloophealth.com/v0.1
    description: Staging partner edge (sandbox credentials)
security: []
paths:
  /billing-customers:
    post:
      tags:
        - Billing Customers
      summary: Create Customer
      description: >-
        Create-or-update ("upsert") a customer, keyed on `email`, within the
        config's payment-provider account. Searches for an existing customer by
        email; if found, updates the most recently created match; otherwise
        creates a new customer. Idempotent on email.
      parameters:
        - in: header
          name: Idempotency-Key
          required: false
          schema:
            type: string
          description: >-
            Deduplicates retried requests with the same key and parameters
            instead of creating a second resource. Recommended: an opaque,
            randomly-generated value such as a UUID.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                  description: >-
                    The upsert match key. Normalized to lowercase and trimmed
                    server-side.
                name:
                  type: string
                  description: Customer name (non-empty when present).
                phone:
                  type: string
                  description: Customer phone (non-empty when present).
                provider_default_invoice_payment_method_id:
                  type: string
                  description: >-
                    Provider payment-method ID to set as the default for future
                    invoices.
                address:
                  type: object
                  properties:
                    line1:
                      type: string
                      description: Street address line 1.
                    line2:
                      type: string
                      description: Street address line 2.
                    city:
                      type: string
                      description: City.
                    state:
                      type: string
                      description: State / province.
                    postal_code:
                      type: string
                      description: Postal code.
                    country:
                      type: string
                      description: Country.
                  description: >-
                    Customer address. Optional fields: `line1`, `line2`, `city`,
                    `state`, `postal_code`, `country`.
                shipping:
                  type: object
                  properties:
                    name:
                      type: string
                      description: Recipient name (required when `shipping` provided).
                    phone:
                      type: string
                      description: Recipient phone.
                    address:
                      type: object
                      properties:
                        line1:
                          type: string
                          description: Street address line 1.
                        line2:
                          type: string
                          description: Street address line 2.
                        city:
                          type: string
                          description: City.
                        state:
                          type: string
                          description: State / province.
                        postal_code:
                          type: string
                          description: Postal code.
                        country:
                          type: string
                          description: Country.
                      description: >-
                        Shipping address (same shape as `address` fields above);
                        `line1` required.
                  required:
                    - name
                    - address
                  description: >-
                    Shipping details. Requires `name` and `address.line1`;
                    optional `phone` and the other address fields.
                metadata:
                  type: object
                  properties:
                    source:
                      type: string
                  description: String key/value pairs.
              required:
                - email
            example:
              email: customer@example.com
              name: Example Customer
              phone: '+000000000000'
              provider_default_invoice_payment_method_id: test_payment_method_id
              metadata:
                source: intake
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      config_id:
                        type: string
                        description: Configuration ID.
                      provider_account_id:
                        type:
                          - string
                          - 'null'
                        description: Provider account ID.
                      provider_customer_id:
                        type: string
                        description: Provider customer ID.
                      payment_provider:
                        type: string
                        description: Provider enum (e.g. `"stripe"`).
                      email:
                        type: string
                        description: Customer email.
                      name:
                        type: string
                        description: Customer name.
                      phone:
                        type:
                          - string
                          - 'null'
                        description: Customer phone.
                      description:
                        type:
                          - string
                          - 'null'
                        description: Customer description.
                      delinquent:
                        type:
                          - boolean
                          - 'null'
                        description: Whether the customer has an unpaid/overdue invoice.
                      address:
                        type:
                          - object
                          - 'null'
                        properties:
                          line1:
                            type:
                              - string
                              - 'null'
                            description: Street address line 1.
                          line2:
                            type:
                              - string
                              - 'null'
                            description: Street address line 2.
                          city:
                            type:
                              - string
                              - 'null'
                            description: City.
                          state:
                            type:
                              - string
                              - 'null'
                            description: State / province.
                          postal_code:
                            type:
                              - string
                              - 'null'
                            description: Postal code.
                          country:
                            type:
                              - string
                              - 'null'
                            description: Country.
                        description: >-
                          Address (`line1`, `line2`, `city`, `state`,
                          `postal_code`, `country`).
                      shipping:
                        type:
                          - object
                          - 'null'
                        properties:
                          name:
                            type:
                              - string
                              - 'null'
                            description: Recipient name.
                          phone:
                            type:
                              - string
                              - 'null'
                            description: Recipient phone.
                          address:
                            type:
                              - object
                              - 'null'
                            properties:
                              line1:
                                type:
                                  - string
                                  - 'null'
                                description: Street address line 1.
                              line2:
                                type:
                                  - string
                                  - 'null'
                                description: Street address line 2.
                              city:
                                type:
                                  - string
                                  - 'null'
                                description: City.
                              state:
                                type:
                                  - string
                                  - 'null'
                                description: State / province.
                              postal_code:
                                type:
                                  - string
                                  - 'null'
                                description: Postal code.
                              country:
                                type:
                                  - string
                                  - 'null'
                                description: Country.
                            description: >-
                              Shipping address (same shape as the `address`
                              fields above).
                        description: Shipping (`name`, `phone`, `address`).
                      default_invoice_payment_method:
                        type:
                          - object
                          - 'null'
                        properties:
                          provider_payment_method_id:
                            type: string
                            description: Payment method ID.
                          type:
                            type: string
                            description: Payment method type (e.g. `"card"`).
                          card:
                            type:
                              - object
                              - 'null'
                            properties:
                              brand:
                                type: string
                                description: Card brand (e.g. `test_card_brand`).
                              last4:
                                type: string
                                description: Last four digits.
                              exp_month:
                                type: number
                                description: Expiration month.
                              exp_year:
                                type: number
                                description: Expiration year.
                            description: Card details; `null` for non-card payment methods.
                        description: >-
                          Default payment method for invoices; `null` when not
                          set.
                      created:
                        type:
                          - number
                          - 'null'
                        description: Unix timestamp.
                      balance:
                        type: number
                        description: >-
                          The customer's balance with the payment provider, in
                          the smallest unit of `currency` (cents for USD).
                          Negative is a credit that applies to the next invoice;
                          positive is an amount added to the next invoice.
                          Counts only amounts not yet applied to an invoice, in
                          the customer's default currency only. `0` for a newly
                          created customer; the existing balance when the
                          request matches and updates an existing customer.
                      currency:
                        type:
                          - string
                          - 'null'
                        description: >-
                          Lowercase ISO currency code for `balance`; `null`
                          until the payment provider sets one.
                      metadata:
                        type: object
                        additionalProperties:
                          type: string
                        description: >-
                          Free-form string key/value pairs attached to the
                          billing customer. `{}` when none are set.
                required:
                  - data
              example:
                data:
                  config_id: test_config_id
                  provider_account_id: test_account_id
                  provider_customer_id: test_customer_id
                  payment_provider: stripe
                  email: customer@example.com
                  name: Example Customer
                  phone: null
                  description: null
                  delinquent: null
                  address: null
                  shipping: null
                  default_invoice_payment_method:
                    provider_payment_method_id: test_payment_method_id
                    type: card
                    card:
                      brand: test_card_brand
                      last4: '4242'
                      exp_month: 12
                      exp_year: 2028
                  created: 1300
                  balance: 0
                  currency: null
                  metadata: {}
        '400':
          description: >-
            ValidationError: Missing/empty `email`; empty body; optional-field
            type failure.
        '401':
          description: Missing or invalid bearer token.
        '403':
          description: >-
            No configuration exists for your account, or provider access has
            been disabled for it.
        '500':
          description: An upstream provider error.
      security:
        - serviceToken: []
        - userToken: []
components:
  securitySchemes:
    serviceToken:
      type: oauth2
      description: >-
        Service (M2M) access token issued by POST /auth/token using the
        client_credentials grant. Required scopes, where known, are listed on
        each operation below.
      flows:
        clientCredentials:
          tokenUrl: https://api.openloophealth.com/v0.1/auth/token
          scopes: {}
    userToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        User access token issued by POST /auth/token via the verification-code
        grant (after Verify a one-time code) or the refresh_token grant.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.