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

# Create Payment

> Posts a patient payment back to the provider's EMR ledger.

<Info>
  Posting payments is an asynchronous operation. The endpoint validates your request, queues the payment, and returns immediately with a `payment_id` and `job_id`. The payment is posted to the EMR by a background worker, and a webhook event is sent to your registered endpoint upon completion.
</Info>

### Request Parameters

#### Required Fields

* **patient\_mrn** (string, required): Medical Record Number (MRN) of the patient the payment belongs to.
* **payment\_method** (string, required): Name of the payment method as configured in the EMR (e.g. `"Card"`). The worker resolves this name to the EMR's internal payment method id at post time.
* **reference\_number** (string, required): Your reference for the payment (e.g. a transaction or receipt number). Reference numbers may be reused across payments — they are not used as a uniqueness key.
* **location** (string, required): Identifier of the EMR location/facility the payment is posted against.
* **amount** (number, required): Payment amount. Must be a positive number.

#### Optional Fields

* **notes** (string, optional): Free-text note recorded with the payment in the EMR.
* **deposit\_date** (string, optional): Deposit date in `YYYY-MM-DD` format. Defaults to today if omitted.

### Example Request

```bash theme={null}
curl -X POST https://api.usecobalt.com/v1/payments \
-H 'Content-Type: application/json' \
-H 'client_id: ci_live_198908HJDKJSH98789OHKJL' \
-H 'client_secret: cs_live_9827hofdsklOYYHJLJh' \
-H 'access_token: 493JKLHIU98789hLKH9HHJH' \
-d '{
    "patient_mrn": "MRN-12345",
    "payment_method": "Card",
    "reference_number": "#123456",
    "location": "1404",
    "amount": 350,
    "notes": "Patient copay collected at front desk",
    "deposit_date": "2026-06-15"
}'
```

### Example Response

```json theme={null}
{
    "success": true,
    "message": "Payment processing. A webhook event will be sent upon completion.",
    "payment_id": "123e4567e89b12d3a456426614174001",
    "job_id": 12345
}
```

The response includes:

* **payment\_id**: Unique identifier for the created payment record.
* **job\_id**: Job execution identifier for tracking the async operation.

### Error Responses

#### Missing or Invalid Field

If a required field is missing or invalid, the API returns a `400` with the specific field name:

```json theme={null}
{
    "success": false,
    "message": "Missing or invalid required field: amount (must be a positive number)"
}
```

#### Patient Not Found

If the patient MRN cannot be resolved to an EMR patient, the API returns a `404`:

```json theme={null}
{
    "success": false,
    "message": "Patient with MRN 'MRN-12345' not found. Please ensure the patient has been synced and has an EMR patient ID."
}
```

#### User Not Found

```json theme={null}
{
    "success": false,
    "message": "User not found."
}
```

### Webhook Notifications

When the payment posting is complete, we will send a webhook to your registered endpoint. Here are examples of what those webhook payloads will look like:

#### Success

```json theme={null}
{
    "id": "evt_1J9X2q2eZvKYlo2CluR9g9gV",
    "access_token_reference_id": "user_1J9X2q2eZvKYlo2Cxyz",
    "object": "event",
    "created": "2026-06-15T10:30:00Z",
    "type": "payment.created",
    "job_id": "12345",
    "data": {
        "payment_id": "123e4567e89b12d3a456426614174001",
        "emr_transaction_id": "13969262",
        "payment_method": "Card",
        "amount": 350,
        "reference_number": "#123456",
        "patient_mrn": "MRN-12345"
    }
}
```

#### Failure

```json theme={null}
{
    "id": "evt_1J9X2q2eZvKYlo2CluR9g9gW",
    "access_token_reference_id": "user_1J9X2q2eZvKYlo2Cxyz",
    "object": "event",
    "created": "2026-06-15T10:35:00Z",
    "type": "payment.failed",
    "job_id": "12345",
    "data": {
        "payment_id": "123e4567e89b12d3a456426614174001",
        "failure_reason": "Failed to post payment"
    }
}
```


## OpenAPI

````yaml POST /payments
openapi: 3.0.0
info:
  title: Cobalt API
  version: 1.0.1
  description: API for interacting with Cobalt's EHR integration services
servers:
  - url: https://api.usecobalt.com/v1
security:
  - ClientCredentials: []
    ClientSecret: []
    AccessToken: []
paths:
  /payments:
    post:
      summary: Create Payment
      description: >-
        Posts a patient payment back to the provider's EMR ledger. This is an
        asynchronous operation that returns immediately with a job_id, and sends
        a webhook notification upon completion.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - patient_mrn
                - payment_method
                - reference_number
                - location
                - amount
              properties:
                patient_mrn:
                  type: string
                  description: >-
                    Medical Record Number (MRN) of the patient the payment
                    belongs to.
                payment_method:
                  type: string
                  description: >-
                    Name of the payment method as configured in the EMR (e.g.
                    "Card"). Resolved to the EMR's internal payment method id at
                    post time.
                reference_number:
                  type: string
                  description: >-
                    Your reference for the payment (e.g. a transaction or
                    receipt number). Reference numbers may be reused across
                    payments.
                location:
                  type: string
                  description: >-
                    Identifier of the EMR location/facility the payment is
                    posted against.
                amount:
                  type: number
                  description: Payment amount. Must be a positive number.
                notes:
                  type: string
                  description: >-
                    Optional free-text note recorded with the payment in the
                    EMR.
                deposit_date:
                  type: string
                  format: date
                  description: >-
                    Optional deposit date (YYYY-MM-DD). Defaults to today if
                    omitted.
      responses:
        '200':
          description: Payment queued successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  payment_id:
                    type: string
                    description: Unique identifier for the created payment record
                  job_id:
                    type: integer
                    description: Job execution identifier for tracking the async operation
        '400':
          description: Bad request - Missing or invalid parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
        '404':
          description: User not found or Patient not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                    example: User not found.
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
components:
  securitySchemes:
    ClientCredentials:
      type: apiKey
      in: header
      name: client_id
    ClientSecret:
      type: apiKey
      in: header
      name: client_secret
    AccessToken:
      type: apiKey
      in: header
      name: access_token

````