I am building an automated process for Business Central and another Web based application that requires me to post some changes to the Purchase Invoice Lines. I am using v2 of the API and gotten to the point of fetching the Purchase Invoices with no issues.
I now need to fetch the relevant Purchase Invoice Lines but in all of the documentation it requires that I pass the id
of the line in the Get statement (See Below).
GET businesscentralPrefix/companies({id})/purchaseInvoiceLines({purchaseInvoiceLineId})
I feel like I am missing a step in the process or possibly a table that will let me link the Purchase Invoice to the relevant lines and give me the Ids but I have not been able to find it.
I have been going through the documentation as well as making various API calls to get the relevant line data.
I am expecting to receive data that will let me identify relevant Purchase Invoice Lines to make modifications to.
There is no additional table linking purchase lines to headers. The only reference between the header and the lines is the Document No.
field in the Purchase Line
table.
This purchaseInvoiceLineId
is an optional parameter if you want to fetch a specific line and this refers to the system id of the line record, but if you want to get all lines in a specific invoice, you can omit this value.
This request will return all lines of the given invoice
GET businesscentralPrefix/companies({id})/purchaseInvoices({id})/purchaseInvoiceLines
You can also fetch invoices along with lines in a single request:
GET businesscentralPrefix/companies({id})/purchaseInvoices?$expand=purchaseInvoiceLines
Or one invoice with its respective lines:
GET businesscentralPrefix/companies({id})/purchaseInvoices({invoiceId})?$expand=purchaseInvoiceLines
Or use OData filter expressions if you want to get lines filtered on other criteria besides the document number, for instance:
businesscentralPrefix/companies({id})/purchaseInvoiceLines?$filter=documentId eq {invoiceId} and lineType eq 'Item'