Autopost Invoices

When inserting data that in the end will result in an account payable, you might want to post the invoice directly. This can be done with a couple of API calls.

Generate Invoice Lines

To generate invoice lines you need to know the key of the voyage that your data relates to. If you dont have the voyage key already you need to get it from the API either by getting it at an earlier stage in your integration or with a separate call in this stage. If you for instance already have the port call key you can get the voyage key by doing a GET request on PortCall.

To generate invoice lines post the below request, where key is the voyage key. For multiple voyages, add multiple keys.

POST /ws/rest/Document/refreshDocumentLines?key=123&key=456&isAccountsPayable=true
Body: empty

To locate the voyage key for Service Order and Bunker Order:

Service Order:
GET /ws/rest/ServiceOrder/{key}
Http header:
fields: {"portCall": {"voyage": {"key":"*"}}}

Bunker Order:
GET /ws/rest/BunkerOrder/{key}
Http header:
fields: {"portCall": {"voyage": {"key":"*"}}}

Then get the new invoice lines, called document lines in the API

Service Orders:
GET /ws/rest/DocumentLine?filter=voyage(IN)(123,456)&filter=document(NULL)
&filter=invoicingStatus.statusTypeCode(EQ)PEN&filter=portCall.key(EQ)118616134&filter=portCost.portAgent.daReference(EQ)DA-123

Bunker Orders:
GET /ws/rest/DocumentLine?filter=voyage(IN)(7173894)&filter=document(NULL)
&filter=invoicingStatus.statusTypeCode(EQ)PEN&filter=portCall.key(EQ)7173995
&filter=bunkerOrderLine.bunkerOrder.key(EQ)8366819

Get invoice defaults (optional)

The below endpoint will give you data that can be used when assembling the invoice. Like bank account, issuing company and so on. If you already have the data you can skip this step.

POST /ws/rest/Document/invoiceDefaults

Header: disablebl = true (only for jvms customers)

Body:
{"documentLines":[{"key":111},{"key":222}], "invoicingStatus": "PEN"}

Assemble invoice

Assemble the invoice with this request

POST /ws/rest/Document/assemble

Header: disablebl = true (only for jvms customers)

​​{
    "bankAccount": "bankAccountNo",
    "businessPartner": "businessPartnerCode",
    "documentCurrency": "USD",
    "documentDate": "2022-02-23T00:00:00",
    "documentLines": [{ "key": 111 }, { "key": 222 }],
    "documentPaymentTerms": [
        {
            "baselineDate": "2022-02-23T00:00:00",
            "baselineTerm": "baselineTermCode",
            "dueDate": "2022-03-02T00:00:00",
            "paymentTerms": "paymentTermsCode",
            "percentage": 100
        }
    ],
    "documentText": "A document text",
    "exchangeRate": 1,
    "exchangeRateDate": "2022-02-23T09:28:26",
    "externalDocumentNo": "1234",
    "issuingCompany": "companyCode",
    "invoicingStatus" : "INV"
}
  • Mandatory fields: documentText, documentDate, issuingCompany, bankAccount, baseLineDate, baseLineTerms, dueDate, paymentTerms and percentage.

  • If payment terms percentage is 100%, there should only be one entry in documentPaymentTerms

  • BaseLineTerm is customer specific and needs to be agreed with customer. The baseline terms can be found at /ws/rest/BaselineTerm

  • PaymentTerms is customer specific and needs to be agreed with customer. The payment terms can be found at /ws/rest/PaymentTerms

The request will return the new invoice, called Document in the API. Keep the Document key to post the document in next step.

Post invoice

The final request will set the status to ready for posting which will cause accounting integrations to pick up the invoice and transfer it to accounting. The Document key is returned the assemble response in previous step.

PUT /ws/rest/Document/789

Header: disablebl = true (only for jvms customers)

{"invoicingStatus":"RFP"}

Last updated