setSalesOrderInvoice mutation
setSalesOrderInvoice is a GraphQL mutation of the Chameleoon MAX API. Send it as POST https://max-api.chameleoon.sk/api/v1/graphql with your API key, see Chameleoon MAX.
Records the invoice that another system issued for the order. Call it after your accounting system or e-shop issues the invoice. It works on a confirmed or completed order.
A field you omit is kept. Null or blank clears it.
Permissions
Requires the order.write and order.read permissions.
Repeated calls
When nothing differs, the result is changed: false. MAX checks this before
expectedExternalId, so a retry after a lost response is not a conflict.
Errors
MAX checks the errors in this order:
CONFLICTwithextensions.reasonORDER_STATUSwhen the order is a draft, cancelled or merged.VALIDATION(fieldinvoice.numberorinvoice.externalId) for a number over 100 characters or an external id over 200 characters.CONFLICTwithextensions.reasonINVOICE_GOVERNED(see below). It is checked beforeINVOICE_CHANGED, so a stale expectation does not hide it.CONFLICTwithextensions.reasonINVOICE_CHANGEDwhen the order's invoice is not the one you expected. Read the order again. Nothing is written.
NOT_FOUND when the order does not exist or your API key cannot see it.
Invoices linked in MAX
While an invoice linked to the order in MAX governs the order's invoice reference, the reference is that invoice's.
- A different number, or clearing the number, returns
CONFLICTwithextensions.reasonINVOICE_GOVERNEDandextensions.invoiceNumberset to the governing number. - A write with the governing number returns
changed: false, whatever itsexternalIdandexpectedExternalId. So does a write ofexternalIdalone. Nothing is written.
Good to know
- The order's history records every change. A change of
invoiceNumberis also a transition in the order's events.invoiceExternalIdis not tracked there, so a change of it alone still publishessales_order.changed, with no transition. - Attach the invoice's PDF to the order as an
INVOICEdocument (attachDocument) and read it fromdocuments. ItsexternalNumberis the invoice number and itsdownloadUrlis the PDF. - For an invoice imported from the accounting system, the PDF is kept with the invoice
instead (
attachInvoiceDocument) and is read fromInvoice.documents.
An error whose path runs below this field does not mean the call failed: the invoice was recorded, so do not retry. See
Mutation.
Arguments
ref:SalesOrderRefInput!· requiredinvoice:SalesOrderInvoiceInput!· required
Returns
Example
Mutation
Code
Variables
Code
Response
Code
Values are illustrative: replace IDs and codes with your own before you send the call.