Skip to content

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.

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 type INVOICE and trigger PUSH that has no clientId, 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 as GET /invoices/<id>.

Answer with HTTP 200 and a JSON body. Anything else fails the activation, as described under When your service does not answer.

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:

Terminal window
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.

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.

PathPropertyTask in the Client Portal (English)
InvoiceInvoiceNumberInvoice Number
InvoiceCustomerCustomer
InvoiceAmountsAmount
InvoiceBaseCurrencyCurrency
InvoiceInvoiceCurrencyINVALID_INVOICE_CURRENCY (no label in any language)
InvoiceDatesDates
InvoiceReferencesYour Reference
Invoiceempty stringTotal sum on invoice (excl. VAT + VAT + Rounding)
Invoice.DebtorCustomerNumberCustomer Number
Invoice.DebtorGLNGLN
Invoice.DebtorCellPhoneCell Phone
Invoice.DebtorNameCustomer Name
Invoice.DebtorCountryCodeCountry Code
Invoice.DebtorIdentificationNumberCustomer Identification Number
Invoice.DebtorBillingAddressBilling Address
Invoice.DebtorEmailE-mail (Edit Customer Information)
Invoice.DebtorLanguageLanguage
Invoice.Debtor.InvoiceAddressAddressCustomer Address
Invoice.Debtor.InvoiceAddressZipZIP Code
Invoice.Debtor.InvoiceAddressCityCity
Invoice.TotalsTotalAmountIncorrect Invoice Amount
Invoice.TotalsVatAmountVAT Amount
Invoice.TotalsRoundingAmountRounding
Invoice.DatesExpireDateExpire Date
Invoice.DatesInvoiceDateInvoice Date
Invoice.ArticleRowsUnitUnit
Invoice.ArticleRowsQuantityQuantity
Invoice.ArticleRowsPricePrice
Invoice.ArticleRowsVatPercentageVAT %
Invoice.ArticleRowsTotalVatTotal VAT
Invoice.ArticleRowsTotalDiscountDiscount %
Invoice.ArticleRowsTotalExclVatExcl. VAT calculation on invoice row
Invoice.ArticleRowsTotalTotal

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.

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:

Terminal window
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.

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 with 400 and a message that starts with External 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.