createInvoice
Requires at least one of the permissions payments:invoice:create or purchase:purchase_invoice:create.
Creates an invoice for a customer (sales invoice) or a supplier (purchase invoice). The partner must exist and at least one line is required. A line can bill a sales order line, and the quantity billed cannot exceed what that order line still has to invoice. An invoice with no linked order is checked against the customer's or supplier's credit limit; an order-linked invoice is not, because its order was already checked. New invoices use the tax-exclusive method. The server calculates every total. A sales invoice needs the invoices create permission; a purchase invoice needs the purchase invoices create permission.
Errors: a failed call returns a GraphQL errors entry, not a field on the result, and data may be null or partial. Read the entry's extensions.code and message; every shape and code is in the Error reference.
Example:
- GraphQL
- cURL
mutation CreateInvoice($input: CreateInvoiceInput!) {
createInvoice(input: $input) {
id
invoiceNumber
supplierCode
supplierDisplayName
supplierName
status
allocations {
id
invoiceNumber
paymentNumber
createdAt
amount
appliedFromAdvance
}
}
}
curl -X POST "https://<api-host>/graphql" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
--data @- <<'EOF'
{
"query": "mutation CreateInvoice($input: CreateInvoiceInput!) {\n createInvoice(input: $input) {\n id\n invoiceNumber\n supplierCode\n supplierDisplayName\n supplierName\n status\n allocations {\n id\n invoiceNumber\n paymentNumber\n createdAt\n amount\n appliedFromAdvance\n }\n }\n}",
"variables": {
"input": {
"invoiceDate": "string",
"items": [
{
"description": "string",
"productId": "id",
"quantity": 0,
"unitPrice": 0,
"variantId": "id"
}
],
"partnerId": "id",
"type": "PURCHASE_INVOICE"
}
}
}
EOF
Variables:
{
"input": {
"invoiceDate": "string",
"items": [
{
"description": "string",
"productId": "id",
"quantity": 0,
"unitPrice": 0,
"variantId": "id"
}
],
"partnerId": "id",
"type": "PURCHASE_INVOICE"
}
}
Response:
{
"data": {
"createInvoice": {
"id": "id",
"invoiceNumber": "string",
"supplierCode": "string",
"supplierDisplayName": "string",
"supplierName": "string",
"status": "APPROVED",
"allocations": [
{
"id": "id",
"invoiceNumber": "string",
"paymentNumber": "string",
"createdAt": "2025-01-15T00:00:00Z",
"amount": 0,
"appliedFromAdvance": true
}
]
}
}
}
Create a sales invoice for an order:
- GraphQL
- cURL
mutation CreateInvoice($input: CreateInvoiceInput!) {
createInvoice(input: $input) {
id
invoiceNumber
status
currency
totalAmount
}
}
curl -X POST "https://<api-host>/graphql" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
--data @- <<'EOF'
{
"query": "mutation CreateInvoice($input: CreateInvoiceInput!) {\n createInvoice(input: $input) {\n id\n invoiceNumber\n status\n currency\n totalAmount\n }\n}",
"variables": {
"input": {
"type": "SALES_INVOICE",
"partnerId": "CUSTOMER_ID",
"orderId": "SALES_ORDER_ID",
"invoiceDate": "2025-01-15",
"items": [
{
"description": "Line description",
"productId": "PRODUCT_ID",
"variantId": "VARIANT_ID",
"quantity": 2,
"unitPrice": 100
}
]
}
}
}
EOF
Variables:
{
"input": {
"type": "SALES_INVOICE",
"partnerId": "CUSTOMER_ID",
"orderId": "SALES_ORDER_ID",
"invoiceDate": "2025-01-15",
"items": [
{
"description": "Line description",
"productId": "PRODUCT_ID",
"variantId": "VARIANT_ID",
"quantity": 2,
"unitPrice": 100
}
]
}
}
Response:
{
"data": {
"createInvoice": {
"id": "INVOICE_ID",
"invoiceNumber": "INVOICE_NUMBER",
"status": "DRAFT",
"currency": "CURRENCY_CODE",
"totalAmount": 200
}
}
}
createInvoice(
input: CreateInvoiceInput!
): Invoice!
Arguments
createInvoice.input ● CreateInvoiceInput! non-null input
The invoice to create.
Type
Invoice object
A sales invoice issued to a customer or a purchase invoice received from a supplier, with its lines, totals, status and settlement.