> Index of every page: https://docs.merchantservicedepot.com/llms.txt

# Create invoice


`POST /v1/invoices`

Send a total, or the lines that make one. With `items` the invoice totals itself — quantity × unitAmount, plus `amountTax`, less `amountDiscount` — and `amount` becomes optional; send it anyway and it is checked against that sum rather than trusted. `amountTax` and `amountDiscount` adjust that line total, so they require `items`. Lines come back in the order you sent them.

For the due date, send either `dueAt` or `paymentTerms` (`due_on_receipt`, `net_7`, `net_15`, `net_30`, `net_60`) — not both. Terms are a derivation: the due date is computed when the invoice is ISSUED, counting calendar days from that moment, so a draft written today and sent next week is due relative to next week. The example below sends `dueAt` because the two are alternatives and a request cannot demonstrate both.

Set an `Idempotency-Key` header derived from the operation (not random per run) so a job that runs twice gets the original invoice back instead of a second one. Amounts are integers in the minor unit — 4999 is $49.99. A decimal is rejected rather than silently charged as a different figure.

Auth: a secret key with the `invoices.create` permission. Returns `201` with Invoice.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `customerId` | body | string | Yes | The customer that owns or receives this resource. |
| `currency` | body | string · ISO 4217 | Yes | A three-letter ISO 4217 currency code. |
| `description` | body | string | No | A merchant-visible description of the resource. |
| `amount` | body | integer · integer · minor units | Yes | A non-negative integer in the currency’s minor unit. 4999 represents $49.99. |
| `items` | body | array | No | The lines being billed. Each carries a description, a quantity, and a unitAmount in minor units; the invoice totals itself from them, so amount becomes optional. |
| `amountTax` | body | integer · integer · minor units | No | Tax added to the line total. Adjusts the lines, so it requires items. |
| `amountDiscount` | body | integer · integer · minor units | No | Discount subtracted from the line total. Adjusts the lines, so it requires items, and may not exceed what is being discounted. |
| `dueAt` | body | string · ISO 8601 timestamp | No | An ISO 8601 timestamp for when the invoice is due. |

## Request

**curl**

```curl
curl -X POST "https://payments-api-sandbox.merchantservicedepot.com/v1/invoices" \
  -H "Authorization: Bearer $MYELA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "customerId": "{{CUSTOMER_ID}}",
  "currency": "USD",
  "description": "Consulting, August",
  "amount": 147375,
  "items": [
    {
      "description": "Consulting, August",
      "quantity": 20,
      "unitAmount": 7500
    }
  ],
  "amountTax": 12375,
  "amountDiscount": 15000,
  "dueAt": "2026-09-01T00:00:00.000Z"
}'
```

**Node**

```node
const res = await fetch("https://payments-api-sandbox.merchantservicedepot.com/v1/invoices", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MYELA_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    "customerId": "{{CUSTOMER_ID}}",
    "currency": "USD",
    "description": "Consulting, August",
    "amount": 147375,
    "items": [
      {
        "description": "Consulting, August",
        "quantity": 20,
        "unitAmount": 7500
      }
    ],
    "amountTax": 12375,
    "amountDiscount": 15000,
    "dueAt": "2026-09-01T00:00:00.000Z"
  }),
});

if (!res.ok) {
  const { error } = await res.json();
  // Branch on error.code — never on error.message.
  throw new Error(error.code);
}
const data = await res.json();
```

**Python**

```python
import os
import uuid
import requests

res = requests.post(
    "https://payments-api-sandbox.merchantservicedepot.com/v1/invoices",
    headers={
        "Authorization": f"Bearer {os.environ['MYELA_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "customerId": "{{CUSTOMER_ID}}",
        "currency": "USD",
        "description": "Consulting, August",
        "amount": 147375,
        "items": [
            {
                "description": "Consulting, August",
                "quantity": 20,
                "unitAmount": 7500
            }
        ],
        "amountTax": 12375,
        "amountDiscount": 15000,
        "dueAt": "2026-09-01T00:00:00.000Z"
    },
)

if not res.ok:
    # Branch on error["code"] — never on error["message"].
    raise RuntimeError(res.json()["error"]["code"])
data = res.json()
```

## Response

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Unique invoice identifier. |
| `object` | "invoice" | Stable resource discriminator. |
| `status` | string | Current invoice state. |
| `invoiceNumber` | string | Your invoice's own number: a per-account sequence behind a prefix you choose. Unique within your account, and yours to quote to a customer — it is not the processor's reference, nor the number on the payment that settles it. |
| `customerId` | string | Customer receiving the invoice. |
| `amount` | integer | Invoice total in minor units. On an itemized invoice this is the computed sum — lines, plus tax, less discount — not a figure set independently of them. |
| `amountPaid` | integer | Amount paid in minor units: `amount` once paid, 0 while open. On a partly paid invoice (`overdue`, or `void` after it), what the first partial payment still holds, net of refunds; check `/attempts` for any later one. Read paid from `status`, not this figure. |
| `currency` | string | Three-letter currency code. |
| `description` | string | Free-text memo, the same field the create call takes as description. Absent when the invoice carries none. |
| `items` | array | The billed lines, in the order they were sent, with amounts in minor units. Absent on an invoice created from a total alone — an amount-only invoice has no lines to report, and none are invented for it. |
| `amountTax` | integer | Tax added to the line total, in minor units. Absent when the invoice carried none, which is not the same as zero. |
| `amountDiscount` | integer | Discount subtracted from the line total, in minor units. Absent when the invoice carried none. |
| `billTo` | object | Who the invoice was addressed to, copied from the customer's default billing address when the invoice was issued. A snapshot, not a live link — a customer who moves house does not rewrite invoices already sent. Absent on a draft, which has not been issued. |
| `paymentTerms` | string | How dueAt was arrived at: due_on_receipt, net_7, net_15, net_30, net_60, or custom when the date was named directly. Absent on invoices issued before terms existed. |
| `issuedAt` | string | When the invoice was issued, which is not when it was created — a draft written on Monday and sent on Friday is issued Friday. Terms count from here. Absent while it is still a draft. |
| `url` | string | Where the customer pays this invoice, on a Myela-hosted page. Present once the invoice has been sent from the portal or by an auto-send recurring invoice; one only created and scheduled through /v1 has none. |
| `pdfUrl` | string | The invoice as a PDF, fronted by your business name. Fetch it with the same API key; it is not a public link. |
| `dueAt` | string | ISO 8601 due timestamp. |
| `collection` | object | Scheduled collection details, when configured. |
| `createdAt` | string | ISO 8601 creation timestamp. |
| `pendingConfirmation` | object | Present only while a charge on this invoice is unresolved. Automatic collection is suspended and the named payment must be reconciled before it resumes. Voiding is refused (409, `details.code` `PAYMENT_PENDING_CONFIRMATION`) until it clears, and still afterwards if the named payment resolved as authorized but never captured. |

```json
{
  "id": "inv_01JEXAMPLE",
  "object": "invoice",
  "status": "open",
  "invoiceNumber": "INV-000123",
  "customerId": "cus_01JEXAMPLE",
  "amount": 147375,
  "amountPaid": 0,
  "currency": "USD",
  "description": "Consulting, August",
  "items": [
    {
      "description": "Consulting, August",
      "quantity": 20,
      "unitAmount": 7500,
      "amount": 150000
    }
  ],
  "amountTax": 12375,
  "amountDiscount": 15000,
  "billTo": {
    "name": "Augusta King",
    "company": "Analytical Engines Ltd",
    "line1": "12 St James Square",
    "city": "London",
    "postalCode": "SW1Y 4LE",
    "country": "GB"
  },
  "paymentTerms": "net_30",
  "issuedAt": "2026-08-19T10:00:00.000Z",
  "url": "https://example.com/pay/8Kd2mQ",
  "pdfUrl": "https://payments-api-sandbox.merchantservicedepot.com/v1/invoices/inv_01JEXAMPLE/pdf",
  "dueAt": "2026-09-01T00:00:00.000Z",
  "collection": {
    "collectAt": "2026-09-01T09:00:00.000Z",
    "attemptCount": 0
  },
  "createdAt": "2026-08-10T20:49:51.653Z",
  "pendingConfirmation": {
    "paymentId": "pay_01JEXAMPLE",
    "since": "2026-09-14T18:04:11.000Z"
  }
}
```

Source: https://docs.merchantservicedepot.com/api-reference/create-invoice/
