Validate invoices from your own system
Some integrations must approve an invoice before Quiddly books it, for example to reject a currency the business does not accept. Quiddly can call a service that you host when an invoice is activated, and your answer decides whether the invoice goes on. This page describes that call, the errors you can return, and what happens when your service does not answer. For the normal create and activate calls, see Create & Book Invoice.
How the call works
Section titled “How the call works”When validation is on, PUT /invoices/<id>/activate does not activate the
invoice at once. First Quiddly saves some choices of the request on the
invoice: the product (productCode, or the default product for the invoice when
it is not given), distributionCode when it is given, and
disableFallbackDistribution only when it is true. The other fields of the
request are not saved, so send them again in the second call. Then Quiddly sends
one POST to your service and waits for the answer. Quiddly sets no time limit
on this call, and the activation request waits for you, so answer quickly.
- URL. The URL of the environment’s enabled webhook
with
typeINVOICEandtriggerPUSHthat has noclientId, where{invoice_id}in the URL is replaced by the invoice id. If there are several such webhooks, Quiddly uses one of them, so keep only one. - Authentication. The header named by the webhook’s key parameter carries the shared key. The request is not signed with an HMAC.
- Body.
{ "invoice": { ... } }, with the invoice in the same shape asGET /invoices/<id>.
Answer with HTTP 200 and a JSON body. Anything else fails the activation, as
described under When your service does not answer.
If the invoice is valid
Section titled “If the invoice is valid”Return 200 with no errors, or an empty list. Quiddly then does not activate
the invoice by itself: it stays as it is. Activate it yourself with a second
call that sets isValidated to true, which skips the validation call:
curl -X PUT "https://$HOST/invoices/$INVOICE_ID/activate" \ -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \ -d '{ "productCode": "INVOICE_SERVICE", "isValidated": true }'Once a successful INVOICE webhook delivery is logged for the invoice, which
includes a successful validation call, Quiddly refuses an activation that does not
set isValidated, with 400 Invoice is currently being validated and cannot be activated again.
If the invoice is not valid
Section titled “If the invoice is not valid”Return 200 with an errors list. Quiddly creates one task for each error it
recognises, sets the invoice to PENDING_AUTHORIZATION and shows the tasks to the
client. To reject an invoice because of its currency, return:
{ "errors": [ { "path": "Invoice", "property": "BaseCurrency" } ]}Quiddly reads only path and property. The other fields of an error (model,
errorCode, errorMessage and ruleType) are accepted but not shown, so a
custom message text never reaches the client. The task is named after the pair of
path and property, in the language the Client Portal is shown in. In
English, the example above shows Currency, and in Swedish and Norwegian
Valuta.
Several errors with the same pair give one task. A pair that is not in the table
below gives no task, but the invoice still moves to PENDING_AUTHORIZATION.
| Path | Property | Task in the Client Portal (English) |
|---|---|---|
Invoice | InvoiceNumber | Invoice Number |
Invoice | Customer | Customer |
Invoice | Amounts | Amount |
Invoice | BaseCurrency | Currency |
Invoice | InvoiceCurrency | INVALID_INVOICE_CURRENCY (no label in any language) |
Invoice | Dates | Dates |
Invoice | References | Your Reference |
Invoice | empty string | Total sum on invoice (excl. VAT + VAT + Rounding) |
Invoice.Debtor | CustomerNumber | Customer Number |
Invoice.Debtor | GLN | GLN |
Invoice.Debtor | CellPhone | Cell Phone |
Invoice.Debtor | Name | Customer Name |
Invoice.Debtor | CountryCode | Country Code |
Invoice.Debtor | IdentificationNumber | Customer Identification Number |
Invoice.Debtor | BillingAddress | Billing Address |
Invoice.Debtor | Email | E-mail (Edit Customer Information) |
Invoice.Debtor | Language | Language |
Invoice.Debtor.InvoiceAddress | Address | Customer Address |
Invoice.Debtor.InvoiceAddress | Zip | ZIP Code |
Invoice.Debtor.InvoiceAddress | City | City |
Invoice.Totals | TotalAmount | Incorrect Invoice Amount |
Invoice.Totals | VatAmount | VAT Amount |
Invoice.Totals | RoundingAmount | Rounding |
Invoice.Dates | ExpireDate | Expire Date |
Invoice.Dates | InvoiceDate | Invoice Date |
Invoice.ArticleRows | Unit | Unit |
Invoice.ArticleRows | Quantity | Quantity |
Invoice.ArticleRows | Price | Price |
Invoice.ArticleRows | VatPercentage | VAT % |
Invoice.ArticleRows | TotalVat | Total VAT |
Invoice.ArticleRows | TotalDiscount | Discount % |
Invoice.ArticleRows | TotalExclVat | Excl. VAT calculation on invoice row |
Invoice.ArticleRows | Total | Total |
What the client sees
Section titled “What the client sees”In the Client Portal, the invoice appears under Errands, in Resolve Invoice
Issue. The client opens it and sees a Failed validation card that lists the
fields that are missing or incorrect, one line per task. The client corrects the
invoice and selects Submit, which saves the invoice and resolves the open
tasks. Resolving a task sends the invoice to your service again: an answer with
errors opens new tasks, and an answer without errors sets the invoice back to
CREATED, ready to be activated with isValidated.
Post the errors yourself
Section titled “Post the errors yourself”You can also report validation errors for an invoice without answering a
validation call. Send them to
POST /errands/system/invoice-validation-errors/<invoiceId> (right
CreateValidationErrorErrands), with the same list:
curl -X POST "https://$HOST/errands/system/invoice-validation-errors/$INVOICE_ID" \ -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \ -d '{ "errors": [ { "path": "Invoice", "property": "BaseCurrency" } ] }'The call creates the tasks and sets the invoice to PENDING_AUTHORIZATION, just
like an answer with errors. GET /errands/system/invoice-validation-errors
(right GetValidationErrorErrands) lists the invoices in PENDING_AUTHORIZATION
that have open validation tasks.
When your service does not answer
Section titled “When your service does not answer”Quiddly makes the validation call once for each activation request, and it does not retry it.
- If your service answers with a status other than
200, or with a body that is not JSON (for example an HTML error page), or if Quiddly cannot connect to it at all (for example because the connection is refused), the activation is refused with400and a message that starts withExternal invoice validation. - If your service accepts the connection but does not answer, the activation request stays open, because Quiddly sets no time limit on the call.
- A call that fails leaves the invoice in the status it had. It is not activated. The choices that were saved before the call, described under How the call works, stay saved on the invoice.
- A call that answers without JSON leaves no entry in the webhook request log. A
call that answers with a status of 400 or above and a JSON body is logged as
FAILED.
When your service is healthy again, activate the invoice again. That repeats the validation call.