> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.joincandidhealth.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.joincandidhealth.com/_mcp/server.

# Import Invoice

POST https://api.joincandidhealth.com/api/import-invoice/v1
Content-Type: application/json

Import an existing invoice from a third party service to reflect state in Candid.

Reference: https://docs.joincandidhealth.com/api-reference/patient-collections/import-invoice/v-1/import-invoice

## Authentication

- OAuth2 — send the obtained token as `Authorization: Bearer <token>`

## Servers

- `https://api.joincandidhealth.com` (Production, default)
- `https://api-staging.joincandidhealth.com` (Staging)
- `https://sandbox-api.joincandidhealth.com` (CandidSandbox)
- `https://staging-api.joincandidhealth.com` (CandidStaging)
- `http://localhost:5050` (Local)

## Request

### Body (application/json)

This endpoint expects a CreateImportInvoiceRequest.

- `external_payment_account_config_id` (UUID, required)
- `patient_external_id` (string, required)
- `external_customer_identifier` (string, required) — Id of the customer in the source system
- `items` (list of InvoiceItemCreate, required)
- `status` (enum, required)
  - Allowed values: `DRAFT`, `OPEN`, `PAID`, `VOID`, `UNCOLLECTIBLE`, `HELD`
- `external_identifier` (string, required) — Id of the invoice being imported in the source system. Warning - This field CANNOT be updated.
- `note` (string, optional)
- `due_date` (date, optional) — If given as None, days_until_due in the payment config will be used to create a default date
- `customer_invoice_url` (string, optional) — Link to the patient view of the invoice in the third-party service

## Response

### 200

- `id` (UUID, required)
- `created_at` (datetime, required)
- `updated_at` (datetime, required)
- `items` (InvoiceItemInfo, required) — The InvoiceItem rollup which contains all claim and service line invoice items
- `patient_external_id` (string, required)
- `external_customer_identifier` (string, required) — Id of the customer in the source system
- `status` (enum, required)
  - Allowed values: `DRAFT`, `OPEN`, `PAID`, `VOID`, `UNCOLLECTIBLE`, `HELD`
- `external_identifier` (string, required) — Id of the invoice being imported in the source system
- `due_date` (date, required)
- `amount_cents` (integer, required) — Total monetary amount (in cents) of all Invoice Items
- `note` (string, optional)
- `customer_invoice_url` (string, optional) — Link to the patient view of the invoice in the third-party service

## Errors

### 422 Unprocessable Entity Error

- `errorName` ("UnprocessableEntityError", required)
- `content` (UnprocessableEntityErrorMessage, required)

### 409 Entity Conflict Error

- `errorName` ("EntityConflictError", required)
- `content` (EntityConflictErrorMessage, required)

## Types

### InvoiceItemCreate

- `attribution` (InvoiceItemAttributionCreate, required) — Points to the claim or service line that this invoice is attributed to
- `amount_cents` (integer, required)

### InvoiceItemInfo

- `claim_invoice_items` (map from UUID to ClaimInvoiceItemInfo, required)
- `unattributed_items` (list of UnattributedInvoiceItem, required)

### UnprocessableEntityErrorMessage

- `message` (string, optional)

### EntityConflictErrorMessage

- `entity_name` (string, required)

### InvoiceItemAttributionCreate

Points to the claim or service line that this invoice is attributed to

- `type`: `service_line_id`
  - `value` (UUID, required)
- `type`: `claim_id`
  - `value` (UUID, required)
- `type`: `unattributed`

### ClaimInvoiceItemInfo

- `service_line_invoice_items` (map from UUID to ServiceLineInvoiceItem, required)
- `claim_invoice_item` (ClaimInvoiceItem, optional)

### UnattributedInvoiceItem

- `amount_cents` (integer, required)

### ServiceLineInvoiceItem

- `service_line_id` (UUID, required)
- `amount_cents` (integer, required)

### ClaimInvoiceItem

- `claim_id` (UUID, required)
- `amount_cents` (integer, required)

## Examples

**Request**

```json
{
  "external_payment_account_config_id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
  "patient_external_id": "patient_external_id",
  "external_customer_identifier": "external_customer_identifier",
  "items": [
    {
      "attribution": {
        "type": "service_line_id",
        "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
      },
      "amount_cents": 1
    },
    {
      "attribution": {
        "type": "service_line_id",
        "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
      },
      "amount_cents": 1
    }
  ],
  "status": "DRAFT",
  "external_identifier": "external_identifier"
}
```

**Response**

```json
{
  "id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
  "created_at": "2024-01-15T09:30:00Z",
  "updated_at": "2024-01-15T09:30:00Z",
  "items": {
    "claim_invoice_items": {
      "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32": {
        "service_line_invoice_items": {
          "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32": {
            "service_line_id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            "amount_cents": 1
          }
        },
        "claim_invoice_item": {
          "claim_id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
          "amount_cents": 1
        }
      }
    },
    "unattributed_items": [
      {
        "amount_cents": 1
      },
      {
        "amount_cents": 1
      }
    ]
  },
  "patient_external_id": "patient_external_id",
  "external_customer_identifier": "external_customer_identifier",
  "status": "DRAFT",
  "external_identifier": "external_identifier",
  "due_date": "2023-01-15",
  "amount_cents": 1,
  "note": "note",
  "customer_invoice_url": "customer_invoice_url"
}
```

**SDK Code**

```python
import requests

url = "https://api.joincandidhealth.com/api/import-invoice/v1"

payload = {
    "external_payment_account_config_id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
    "patient_external_id": "patient_external_id",
    "external_customer_identifier": "external_customer_identifier",
    "items": [
        {
            "attribution": {
                "type": "service_line_id",
                "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
            },
            "amount_cents": 1
        },
        {
            "attribution": {
                "type": "service_line_id",
                "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
            },
            "amount_cents": 1
        }
    ],
    "status": "DRAFT",
    "external_identifier": "external_identifier"
}
headers = {
    "Authorization": "<token>.",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.joincandidhealth.com/api/import-invoice/v1';
const options = {
  method: 'POST',
  headers: {Authorization: '<token>.', 'Content-Type': 'application/json'},
  body: '{"external_payment_account_config_id":"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32","patient_external_id":"patient_external_id","external_customer_identifier":"external_customer_identifier","items":[{"attribution":{"type":"service_line_id","value":"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"},"amount_cents":1},{"attribution":{"type":"service_line_id","value":"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"},"amount_cents":1}],"status":"DRAFT","external_identifier":"external_identifier"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.joincandidhealth.com/api/import-invoice/v1"

	payload := strings.NewReader("{\n  \"external_payment_account_config_id\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\",\n  \"patient_external_id\": \"patient_external_id\",\n  \"external_customer_identifier\": \"external_customer_identifier\",\n  \"items\": [\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    },\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    }\n  ],\n  \"status\": \"DRAFT\",\n  \"external_identifier\": \"external_identifier\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "<token>.")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.joincandidhealth.com/api/import-invoice/v1")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<token>.'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"external_payment_account_config_id\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\",\n  \"patient_external_id\": \"patient_external_id\",\n  \"external_customer_identifier\": \"external_customer_identifier\",\n  \"items\": [\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    },\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    }\n  ],\n  \"status\": \"DRAFT\",\n  \"external_identifier\": \"external_identifier\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.joincandidhealth.com/api/import-invoice/v1")
  .header("Authorization", "<token>.")
  .header("Content-Type", "application/json")
  .body("{\n  \"external_payment_account_config_id\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\",\n  \"patient_external_id\": \"patient_external_id\",\n  \"external_customer_identifier\": \"external_customer_identifier\",\n  \"items\": [\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    },\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    }\n  ],\n  \"status\": \"DRAFT\",\n  \"external_identifier\": \"external_identifier\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.joincandidhealth.com/api/import-invoice/v1', [
  'body' => '{
  "external_payment_account_config_id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
  "patient_external_id": "patient_external_id",
  "external_customer_identifier": "external_customer_identifier",
  "items": [
    {
      "attribution": {
        "type": "service_line_id",
        "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
      },
      "amount_cents": 1
    },
    {
      "attribution": {
        "type": "service_line_id",
        "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
      },
      "amount_cents": 1
    }
  ],
  "status": "DRAFT",
  "external_identifier": "external_identifier"
}',
  'headers' => [
    'Authorization' => '<token>.',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.joincandidhealth.com/api/import-invoice/v1");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<token>.");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"external_payment_account_config_id\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\",\n  \"patient_external_id\": \"patient_external_id\",\n  \"external_customer_identifier\": \"external_customer_identifier\",\n  \"items\": [\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    },\n    {\n      \"attribution\": {\n        \"type\": \"service_line_id\",\n        \"value\": \"d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32\"\n      },\n      \"amount_cents\": 1\n    }\n  ],\n  \"status\": \"DRAFT\",\n  \"external_identifier\": \"external_identifier\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<token>.",
  "Content-Type": "application/json"
]
let parameters = [
  "external_payment_account_config_id": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
  "patient_external_id": "patient_external_id",
  "external_customer_identifier": "external_customer_identifier",
  "items": [
    [
      "attribution": [
        "type": "service_line_id",
        "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
      ],
      "amount_cents": 1
    ],
    [
      "attribution": [
        "type": "service_line_id",
        "value": "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32"
      ],
      "amount_cents": 1
    ]
  ],
  "status": "DRAFT",
  "external_identifier": "external_identifier"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.joincandidhealth.com/api/import-invoice/v1")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```