Skip to content

Create Invoice

Creates an invoice for one or more order items. The same eligibility checks as the admin Invoice screen apply (the order must not be closed, marked fraud, or paid through PayPal Standard — those orders are hard-blocked from invoicing). Each item's requested quantity is validated against its still-invoiceable quantity, qty_to_invoice, before the invoice is created.

The mutation returns the created invoice's scalar fields plus the linked order object (the full order resource — see Get Order Detail for every order sub-field). The nested items connection and the order { addresses { edges { node } } } connection are not resolved on a mutation payload — fetch them with a follow-up adminInvoice(id:) query (or REST GET /api/admin/invoices/{id}) using the returned id / _id.

Prerequisites

The example targets an order with invoiceable items. If your order has no items with qty_to_invoice > 0 (already fully invoiced / closed / fraud / paypal_standard payment method) the mutation returns "There is nothing to invoice on this order." — pick an order with outstanding qty to invoice.

Operation

OperationType
createAdminInvoiceMutation

Input

FieldTypeDescription
orderIdInt!The order to invoice.
items[{ orderItemId, quantity }]!One entry per order item, with the quantity to invoice. Each quantity must be ≤ that item's still-invoiceable qty_to_invoice.
canCreateTransactionBooleanOptional, default false. The admin Create Transaction checkbox — when true, also records an order transaction for the invoice amount against the order's payment method.

Response shape notes

  • The mutation payload resolves the invoice's scalar fields + the order object's scalar fields (it's the full order resource — _id, incrementId, status, statusLabel, channelName, customerEmail, customerFirstName, customerLastName, totals, … — see Get Order Detail for the complete list). It does not resolve the items connection or order { addresses } — those are available on the adminInvoice(id:) detail query (where items { edges { node } } and order { addresses { edges { node } } } resolve fully).
  • There is no top-level orderId — the order id is order { _id }.
  • id is the resource IRI (/api/admin/invoices/88); _id is the numeric id.

Errors

ConditionMessage
Order is closedClosed orders cannot be invoiced.
Order is fraudFraud orders cannot be invoiced.
Order paid with PayPal StandardInvoices cannot be created for orders paid through PayPal Standard.
Nothing to invoiceThere is nothing to invoice on this order.
No permissionYou do not have permission to create invoices.
Items missingAt least one item with a positive quantity is required.
Qty exceeds availableRequested quantity exceeds the available quantity for the given SKU (the message names the SKU and both quantities).
Save failedCould not create the invoice.

Released under the MIT License.