Mercury: Create an invoice (accounts receivable)
Mercury books.createBooksInvoice: arguments, response, policy and SDK examples.
← Books operations · Get started
Operation mercury.createbooksinvoice
Provider route: POST /books/invoices. Alter supplies the connection’s credentials and routing.
Call through Alter
Section titled “Call through Alter”Install @alter-ai/sdk @alter-ai/mercury with npm, or alter-sdk-mercury with pip. Supply your connected customer’s grant ID and the arguments described below.
import { App } from "@alter-ai/sdk";import { MercuryIntegration } from "@alter-ai/mercury";
async function execute(input: Parameters<MercuryIntegration["books"]["createBooksInvoice"]>[0]) { const app = new App({ apiKey: process.env.ALTER_API_KEY! }); try { const provider = new MercuryIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! }); const call = await provider.books.createBooksInvoice(input); const result = await call.wait(); return result.bodyJson(); } finally { await app.close(); }}import osfrom alter_sdk import Appfrom alter_sdk_mercury import MercuryIntegration
async def execute(arguments): async with App(api_key=os.environ["ALTER_API_KEY"]) as app: provider = MercuryIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]}) call = await provider.books.create_books_invoice(arguments) result = await call.wait() return result.body_json()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
query | object | Optional | Additional keys: not allowed |
query.booksId | string | Optional | The Books instance to act on. Must be the token organization’s own instance, which it defaults to. Format: uuid |
headers | object | Optional | Additional keys: not allowed |
headers.Idempotency-Key | string | Optional | |
body | Model | Optional | Expand Create an invoice (accounts receivable) — request body — body |
Referenced models: Create an invoice (accounts receivable) — request body — body
Response
Section titled “Response”Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | JSON | Root | |
$ (anyOf 1) | Model | Alternative | Expand Edit an invoice (accounts receivable) — response body — amount Remaining, customer, display Status, due Date, effective Date, gross Amount, id, lines, notes, payment Applications, reference Number, status |
$ (anyOf 2) | Model | Alternative | Expand Create an invoice (accounts receivable) — response body — customer, due Date, effective Date, gross Amount, message, reference Number, sync Status |
Referenced models: Edit an invoice (accounts receivable) — response body — amount Remaining, customer, display Status, due Date, effective Date, gross Amount, id, lines, notes, payment Applications, reference Number, status, Create an invoice (accounts receivable) — response body — customer, due Date, effective Date, gross Amount, message, reference Number, sync Status
Schemas
Section titled “Schemas”4 more schemas are linked from the tables above, on the schema pages.
Edit an invoice (accounts receivable) — response body — amount Remaining, customer, display Status, due Date, effective Date, gross Amount, id, lines, notes, payment Applications, reference Number, status
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | An invoice (accounts receivable) recorded in Books, with its lines and the payments applied to it. |
amountRemaining | JSON | Required within parent | |
amountRemaining (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
amountRemaining (allOf 2) | JSON | All variants apply | The amount still owed after applied payments, in dollars. |
customer | JSON | Optional | |
customer (anyOf 1) | JSON | Alternative | |
customer (anyOf 1) (allOf 1) | Model | All variants apply | Expand Create an invoice (accounts receivable) — response body — customer, due Date, effective Date, gross Amount, message, reference Number, sync Status customer id, name |
customer (anyOf 1) (allOf 2) | JSON | All variants apply | The customer the invoice is billed to. Omitted when the invoice has no customer. |
customer (anyOf 2) | null | Alternative | |
displayStatus | JSON | Required within parent | |
displayStatus (allOf 1) | string | All variants apply | Known values: open, paid, draft, cancelled, overdue, partiallyPaid, processing |
displayStatus (allOf 2) | JSON | All variants apply | The status as shown to users, derived from `status`, the due date, and payments: also `overdue` (open and past due) and `partiallyPaid` (open with some payment applied). |
dueDate | JSON | Optional | |
dueDate (anyOf 1) | JSON | Alternative | |
dueDate (anyOf 1) (allOf 1) | string | All variants apply | Format: date |
dueDate (anyOf 1) (allOf 2) | JSON | All variants apply | The due date. Omitted when none is set. |
dueDate (anyOf 2) | null | Alternative | |
effectiveDate | JSON | Required within parent | |
effectiveDate (allOf 1) | string | All variants apply | Format: date |
effectiveDate (allOf 2) | JSON | All variants apply | The invoice date. |
grossAmount | JSON | Required within parent | |
grossAmount (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
grossAmount (allOf 2) | JSON | All variants apply | The total of all lines, in dollars. |
id | string | Required within parent | The identifier of the invoice. Format: base58 (max length 22) |
lines | array | Required within parent | The line items. |
lines[] | Model | Each item | Expand Edit an invoice (accounts receivable) — response body — amount Remaining, customer, display Status, due Date, effective Date, gross Amount, id, lines, notes, payment Applications, reference Number, status lines item |
notes | JSON | Optional | |
notes (anyOf 1) | string | Alternative | The invoice's note, as shown in the Note field of the Books invoice in Mercury. Omitted when it has none. |
notes (anyOf 2) | null | Alternative | |
paymentApplications | array | Required within parent | The payments applied. Empty when none. |
paymentApplications[] | Model | Each item | Expand Edit an invoice (accounts receivable) — response body — amount Remaining, customer, display Status, due Date, effective Date, gross Amount, id, lines, notes, payment Applications, reference Number, status payment Applications item |
referenceNumber | JSON | Optional | |
referenceNumber (anyOf 1) | string | Alternative | The invoice number, as shown in the Invoice number field of the Books invoice in Mercury (for example `INV-1042`). Omitted when it has none. |
referenceNumber (anyOf 2) | null | Alternative | |
status | JSON | Required within parent | |
status (allOf 1) | string | All variants apply | Known values: open, paid, draft, cancelled, processing |
status (allOf 2) | JSON | All variants apply | The stored lifecycle status: `draft`, `open`, `processing`, `paid`, or `cancelled`. |
Referenced models: Create a product — response body — unit Price value, Create an invoice (accounts receivable) — response body — customer, due Date, effective Date, gross Amount, message, reference Number, sync Status customer id, name, Edit an invoice (accounts receivable) — response body — amount Remaining, customer, display Status, due Date, effective Date, gross Amount, id, lines, notes, payment Applications, reference Number, status lines item, Edit an invoice (accounts receivable) — response body — amount Remaining, customer, display Status, due Date, effective Date, gross Amount, id, lines, notes, payment Applications, reference Number, status payment Applications item
Create an invoice (accounts receivable) — response body — customer, due Date, effective Date, gross Amount, message, reference Number, sync Status
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | An invoice that was created in Mercury Invoicing but has not synced to Books yet, so it has no Books ID. Returned with HTTP 202. |
customer | JSON | Required within parent | |
customer (allOf 1) | Model | All variants apply | Expand Create an invoice (accounts receivable) — response body — customer, due Date, effective Date, gross Amount, message, reference Number, sync Status customer id, name |
customer (allOf 2) | JSON | All variants apply | The customer the invoice is billed to. |
dueDate | JSON | Required within parent | |
dueDate (allOf 1) | string | All variants apply | Format: date |
dueDate (allOf 2) | JSON | All variants apply | The due date. |
effectiveDate | JSON | Required within parent | |
effectiveDate (allOf 1) | string | All variants apply | Format: date |
effectiveDate (allOf 2) | JSON | All variants apply | The date Books records the invoice on: the earlier of the invoice date and the due date. |
grossAmount | JSON | Required within parent | |
grossAmount (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
grossAmount (allOf 2) | JSON | All variants apply | The total of all line items, in dollars. |
message | string | Required within parent | What happened and how to find the invoice once it has synced. |
referenceNumber | string | Required within parent | The invoice number, unique among the organization's Mercury invoices. Once the invoice has synced, filter the invoice list by it to find the invoice. |
syncStatus | JSON | Required within parent | |
syncStatus (allOf 1) | string | All variants apply | Known values: pending |
syncStatus (allOf 2) | JSON | All variants apply | Always `pending`. A created invoice has an `id` instead. |
Referenced models: Create a product — response body — unit Price value, Create an invoice (accounts receivable) — response body — customer, due Date, effective Date, gross Amount, message, reference Number, sync Status customer id, name
Create an invoice (accounts receivable) — request body — body
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | A request to create a single invoice (accounts receivable). Additional keys: not allowed |
customer | JSON | Required within parent | |
customer (allOf 1) | string | All variants apply | The customer who will receive the invoice. Use the /api/v1/ar/customers endpoint to list your customers and find the corresponding id, or create a new customer first. Format: uuid |
customer (allOf 2) | JSON | All variants apply | The customer to bill (the Customer field of the form): a Mercury Invoicing customer ID of this organization, from the Mercury Invoicing customers API (`/ar/customers`). |
dueDate | JSON | Required within parent | |
dueDate (allOf 1) | string | All variants apply | Format: date |
dueDate (allOf 2) | JSON | All variants apply | The due date (the Due date field of the form), YYYY-MM-DD. |
effectiveDate | JSON | Required within parent | |
effectiveDate (allOf 1) | string | All variants apply | Format: date |
effectiveDate (allOf 2) | JSON | All variants apply | The invoice date (the Invoice date field of the form), YYYY-MM-DD. Books records the invoice on the earlier of this and `dueDate`. |
lines | array | Required within parent | The line items (the Line items table of the form). At least one is required. Minimum items: 1 |
lines[] | Model | Each item | Expand Create an invoice (accounts receivable) — request body — body lines item |
notes | JSON | Optional | |
notes (anyOf 1) | string | Alternative | An optional note (the Note field of the form). |
notes (anyOf 2) | null | Alternative | |
referenceNumber | string | Required within parent | The invoice number, as in the Invoice number field of the form (for example `INV-1042`): the number the business gives the invoice and its customer sees. Required, 1 to 299 characters; leading and trailing whitespace is stripped. With the Mercury Invoicing integration it becomes the Mercury Invoicing invoice number and must be unique among all of the organization's Mercury invoices, of any status. Without it, it is stored only in Books, which rejects a second invoice with the same invoice number for the same customer. Maximum length: 299 Minimum length: 1 |
Referenced models: Create an invoice (accounts receivable) — request body — body lines item
Create a product — response body — unit Price value
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | JSON | Root | |
$ (anyOf 1) | number | Alternative | A dollar amount Format: double |
$ (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
Policy, approvals and errors
Section titled “Policy, approvals and errors”SDK function policy ID: mercury.createbooksinvoice. Catalog operation: mercury:createBooksInvoice. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.
Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.