Create Purchase Invoice

Prev Next
Post
/softera/softeraEInvoice/v2.0/companies({companyId})/purchaseInvoices

Creates a draft purchase invoice. vendorNumber or vendorId is required. You can include purchaseInvoiceLines in the body. Use $expand=purchaseInvoiceLines to have the created lines included in the response. Send apiTotalAmountExclVAT and apiTotalAmountInclVAT with the totals calculated in your system. When Check VAT Mismatch in API Request is enabled in E-Invoice Setup, the amount excluding VAT must match the amount calculated by Business Central (error "Amounts excl. VAT doesn't match."). A VAT difference is corrected automatically only when Allow VAT Auto Correction is enabled and the difference does not exceed Max. VAT Difference Allowed in General Ledger Setup; otherwise the request fails with "VAT amount mismatched by %1, which exceeds the maximum allowed.". When the document is posted, both totals must match the document amounts, otherwise posting fails with "... must match.". Documents created via the API are marked "Created via API" and cannot be edited by users unless Allow API Documents Edit is enabled.

Security
OAuth
FlowClient Credentials
Token URLhttps://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token
Scopes:
https://api.businesscentral.dynamics.com/.defaultGrants the permissions assigned to the Microsoft Entra ID application in Business Central
Path parameters
companyId
string (uuid) Required

GUID for targeted Company

Example54c4066e-2b2b-4118-ac75-7dfea25be205
Query parameters
$expand
string

OData $expand for purchase invoices. Supported navigations: purchaseInvoiceLines, dimensionSetLines, pdfDocument, attachments, documentAttachments. Line navigations can be nested, e.g. purchaseInvoiceLines($expand=dimensionSetLines,location).

ExamplepurchaseInvoiceLines,dimensionSetLines
Body parameters
headerOnly

Header-only invoice

{
  "invoiceDate": "2025-04-02",
  "postingDate": "2025-04-02",
  "dueDate": "2025-04-12",
  "vendorNumber": "V000045",
  "payToVendorNumber": "V000045",
  "currencyCode": "EUR",
  "vendorInvoiceNumber": "PIN00000134"
}
withLines

Invoice with lines (+$expand)

{
  "invoiceDate": "2025-04-02",
  "postingDate": "2025-04-02",
  "dueDate": "2025-04-12",
  "vendorNumber": "V000045",
  "payToVendorNumber": "V000045",
  "currencyCode": "EUR",
  "vendorInvoiceNumber": "PIN00000134",
  "purchaseInvoiceLines": [
    {
      "lineType": "Comment",
      "lineObjectNumber": "",
      "description": "Invoice No. PIN00000134:",
      "quantity": 0,
      "unitCost": 0,
      "discountAmount": 0,
      "discountPercent": 0,
      "taxCode": ""
    },
    {
      "accountId": "ded8a20e-3f41-ec11-a458-000d3adf1e39",
      "lineType": "Account",
      "lineObjectNumber": "5001",
      "description": "Service Revenue",
      "quantity": 1,
      "unitCost": 300,
      "discountAmount": 0,
      "discountPercent": 0,
      "taxCode": "F PASL21"
    },
    {
      "lineType": "Item",
      "lineObjectNumber": "Z0000001",
      "description": "Sulankstoma kėdė",
      "quantity": 10,
      "unitCost": 50,
      "discountAmount": 0,
      "discountPercent": 0,
      "taxCode": "A PREK21"
    }
  ]
}
withLineDimensions

Invoice with lines, deferral and API totals (+$expand=purchaseInvoiceLines)

{
  "invoiceDate": "2025-03-14",
  "postingDate": "2025-03-14",
  "dueDate": "2025-03-29",
  "vendorInvoiceNumber": "KP50055",
  "vendorNumber": "T00001",
  "payToVendorNumber": "T00001",
  "shipToName": "Elgerta Polska",
  "shipToAddressLine1": "Warsawa ul 154",
  "shipToCity": "Warsawa",
  "shipToCountry": "PL",
  "currencyCode": "EUR",
  "pricesIncludeTax": false,
  "apiTotalAmountExclVAT": 500,
  "apiTotalAmountInclVAT": 605,
  "postingDescription": "Furniture Ltd. TSF24425345",
  "purchaseInvoiceLines": [
    {
      "lineType": "Item",
      "lineObjectNumber": "Z0000001",
      "unitOfMeasureCode": "VNT",
      "unitCost": 1,
      "quantity": 500,
      "taxCode": "A PREK21",
      "expectedReceiptDate": "2025-03-14",
      "locationCode": "CENTRINIS",
      "deferralCode": "1Y"
    }
  ]
}
Expand All
object

Writable purchase invoice fields. On create, vendorNumber or vendorId must be provided. purchaseInvoiceLines and dimensionSetLines can be included for a deep insert.

invoiceDate
string (date)
Example2025-04-02
postingDate
string (date)
Example2025-04-02
dueDate
string (date)
Example2025-04-12
vendorInvoiceNumber
string
Max length35
ExampleKP50055
vendorOrderNumber
string
Max length35
ExamplePO12345
postingDescription
string
ExamplePirkimo sąskaita faktūra KP50055
vendorId
string (uuid)
vendorNumber
string
Max length20
ExampleT00001
payToVendorId
string (uuid)
payToVendorNumber
string
Max length20
ExampleT00001
shipToName
string
Max length100
ExampleElgerta Polska
shipToContact
string
Max length100
Example
buyFromAddressLine1
string
ExampleGedimino pr. 1
buyFromAddressLine2
string
Example
buyFromCity
string
Max length30
ExampleVilnius
buyFromCountry
string
Max length10
ExampleLT
buyFromState
string
Max length30
Example
buyFromPostCode
string
Max length20
ExampleLT-01103
shipToAddressLine1
string
ExampleWarsawa ul 154
shipToAddressLine2
string
Example
shipToCity
string
Max length30
ExampleWarsawa
shipToCountry
string
Max length10
ExamplePL
shipToState
string
Max length30
Example
shipToPostCode
string
Max length20
Example
shortcutDimension1Code
string
ExamplePIRK
shortcutDimension2Code
string
Example333
currencyId
string (uuid)
currencyCode
string
ExampleEUR
paymentMethodCode
string
ExampleBANK
pricesIncludeTax
boolean
Examplefalse
userId
string

Assigned User ID (BC user name, not a GUID).

ExamplePAULIUS
purchaseInvoiceLines
Array of object (purchaseInvoiceLineRequest)
object

Writable purchase invoice line fields. documentId is filled automatically when the line is created under a purchase invoice. documentId, sequence and lineObjectNumber cannot be changed once set.

documentId
string (uuid)
sequence
integer
Example10000
itemId
string (uuid)
accountId
string (uuid)
lineType
string
Valid values[ "Comment", "Account", "Item", "Resource", "Fixed_x0020_Asset", "Charge", "Allocation_x0020_Account" ]
ExampleItem
lineObjectNumber
string
Max length20
ExampleZ0000001
locationCode
string
Max length10
ExampleCENTRINIS
description
string
Max length100
ExampleSulankstoma kėdė
unitOfMeasureId
string (uuid)
unitOfMeasureCode
string
Max length10
ExampleVNT
taxCode
string
Max length50
ExampleA PREK21
unitCost
number
Example100.1234
quantity
number
Example20
discountAmount
number
Example0
discountPercent
number
Example0
discountAppliedBeforeTax
boolean
amountExcludingTax
number
Example2002.47
amountIncludingTax
number
Example2422.99
invoiceDiscountAllocation
number
Example0
netAmount
number
Example2002.47
netTaxAmount
number
Example420.52
netAmountIncludingTax
number
Example2422.99
expectedReceiptDate
string (date)
Example2025-04-02
itemVariantId
string (uuid)
deferralCode
string
Example1Y
shortcutDimension1Code
string
ExamplePIRK
shortcutDimension2Code
string
Example333
dimensionSetLines
Array of object (dimensionSetLine)
object

Dimension set line (standard page "APIV2 - Dimension Set Lines"). If the customer, vendor, G/L account or item has default dimensions, overriding them on a document line needs additional PATCH requests; without default dimensions, send the dimensions with the line in the same request. For documents with hundreds of lines, post dimensions in a separate $batch request.

id
string (uuid)

SystemId of the dimension (not of the line)

code
string
ExamplePADALINYS
valueId
string (uuid)
valueCode
string
ExampleADM
dimensionSetLines
Array of object (dimensionSetLine)
object

Dimension set line (standard page "APIV2 - Dimension Set Lines"). If the customer, vendor, G/L account or item has default dimensions, overriding them on a document line needs additional PATCH requests; without default dimensions, send the dimensions with the line in the same request. For documents with hundreds of lines, post dimensions in a separate $batch request.

id
string (uuid)

SystemId of the dimension (not of the line)

code
string
ExamplePADALINYS
valueId
string (uuid)
valueCode
string
ExampleADM
discountAmount
number
Example0
discountAppliedBeforeTax
boolean
Exampletrue
totalAmountIncludingTax
number
Example605
apiTotalAmountExclVAT
number

Total excluding VAT as calculated by the external system. Compared with the amount calculated by Business Central when Check VAT Mismatch in API Request is enabled.

Example500
apiTotalAmountInclVAT
number

Total including VAT as calculated by the external system. Used for the VAT mismatch check and, when Allow VAT Auto Correction is enabled, to correct VAT differences within Max. VAT Difference Allowed.

Example605
locationCode
string
ExampleCENTRINIS
documentLink
string

URL stored as a record link on the document.

Examplehttps://example.com/invoices/KP50055.pdf
documentNote
string

Text stored as a record note on the document.

Example
Responses
201

Created

Headers
Location
string (uri)
URL of the created purchase invoice
Expand All
object
id
string (uuid)
number
string
Max length20
ExamplePIN00000134
invoiceDate
string (date)
Example2025-04-02
postingDate
string (date)
Example2025-04-02
dueDate
string (date)
Example2025-04-12
vendorInvoiceNumber
string
Max length35
ExampleKP50055
vendorOrderNumber
string
Max length35
ExamplePO12345
postingDescription
string
ExamplePirkimo sąskaita faktūra KP50055
vendorId
string (uuid)
vendorNumber
string

Buy-from vendor number. Either vendorId or vendorNumber is required on create.

Max length20
ExampleT00001
vendorName
string
Max length100
ExampleSoftera Baltic, UAB
payToName
string
Max length100
ExampleSoftera Baltic, UAB
payToContact
string
Max length100
Example
payToVendorId
string (uuid)
payToVendorNumber
string
Max length20
ExampleT00001
shipToName
string
Max length100
ExampleElgerta Polska
shipToContact
string
Max length100
Example
buyFromAddressLine1
string
ExampleGedimino pr. 1
buyFromAddressLine2
string
Example
buyFromCity
string
Max length30
ExampleVilnius
buyFromCountry
string
Max length10
ExampleLT
buyFromState
string
Max length30
Example
buyFromPostCode
string
Max length20
ExampleLT-01103
shipToAddressLine1
string
ExampleWarsawa ul 154
shipToAddressLine2
string
Example
shipToCity
string
Max length30
ExampleWarsawa
shipToCountry
string
Max length10
ExamplePL
shipToState
string
Max length30
Example
shipToPostCode
string
Max length20
Example
payToAddressLine1
string
ExampleGedimino pr. 1
payToAddressLine2
string
Example
payToCity
string
Max length30
ExampleVilnius
payToCountry
string
Max length10
ExampleLT
payToState
string
Max length30
Example
payToPostCode
string
Max length20
ExampleLT-01103
shortcutDimension1Code
string
ExamplePIRK
shortcutDimension2Code
string
Example333
currencyId
string (uuid)
currencyCode
string
ExampleEUR
orderId
string (uuid)
orderNumber
string
Max length20
Example
paymentMethodCode
string
ExampleBANK
pricesIncludeTax
boolean
Examplefalse
userId
string

Assigned User ID (BC user name, not a GUID).

ExamplePAULIUS
purchaseInvoiceLines
Array of object (purchaseInvoiceLine)
object
id
string (uuid)
documentId
string (uuid)
sequence
integer
Example10000
itemId
string (uuid)
accountId
string (uuid)
lineType
string
Valid values[ "Comment", "Account", "Item", "Resource", "Fixed_x0020_Asset", "Charge", "Allocation_x0020_Account" ]
ExampleItem
lineObjectNumber
string
Max length20
ExampleZ0000001
locationCode
string
Max length10
ExampleCENTRINIS
description
string
Max length100
ExampleSulankstoma kėdė
unitOfMeasureId
string (uuid)
unitOfMeasureCode
string
Max length10
ExampleVNT
taxCode
string
Max length50
ExampleA PREK21
unitCost
number
Example100.1234
quantity
number
Example20
discountAmount
number
Example0
discountPercent
number
Example0
discountAppliedBeforeTax
boolean
amountExcludingTax
number
Example2002.47
taxPercent
number
Example21
totalTaxAmount
number
Example420.52
amountIncludingTax
number
Example2422.99
invoiceDiscountAllocation
number
Example0
netAmount
number
Example2002.47
netTaxAmount
number
Example420.52
netAmountIncludingTax
number
Example2422.99
expectedReceiptDate
string (date)
Example2025-04-02
itemVariantId
string (uuid)
deferralCode
string
Example1Y
shortcutDimension1Code
string
ExamplePIRK
shortcutDimension2Code
string
Example333
dimensionSetLines
Array of object (dimensionSetLine)
object

Dimension set line (standard page "APIV2 - Dimension Set Lines"). If the customer, vendor, G/L account or item has default dimensions, overriding them on a document line needs additional PATCH requests; without default dimensions, send the dimensions with the line in the same request. For documents with hundreds of lines, post dimensions in a separate $batch request.

id
string (uuid)

SystemId of the dimension (not of the line)

code
string
ExamplePADALINYS
consolidationCode
string
Example
parentId
string (uuid)
parentType
string
Valid values[ "_x0020_", "Journal_x0020_Line", "Sales_x0020_Order", "Sales_x0020_Order_x0020_Line", "Sales_x0020_Quote", "Sales_x0020_Quote_x0020_Line", "Sales_x0020_Credit_x0020_Memo", "Sales_x0020_Credit_x0020_Memo_x0020_Line", "Sales_x0020_Invoice", "Sales_x0020_Invoice_x0020_Line", "Purchase_x0020_Invoice", "Purchase_x0020_Invoice_x0020_Line", "General_x0020_Ledger_x0020_Entry", "Time_x0020_Registration_x0020_Entry", "Sales_x0020_Shipment", "Sales_x0020_Shipment_x0020_Line", "Purchase_x0020_Receipt", "Purchase_x0020_Receipt_x0020_Line", "Purchase_x0020_Order", "Purchase_x0020_Order_x0020_Line", "Purchase_x0020_Credit_x0020_Memo", "Purchase_x0020_Credit_x0020_Memo_x0020_Line" ]
ExampleSales_x0020_Invoice
displayName
string
ExamplePadalinys
valueId
string (uuid)
valueCode
string
ExampleADM
valueConsolidationCode
string
Example
valueDisplayName
string
ExampleAdministracija
location
object (location)

Location (standard page "APIV2 - Locations").

id
string (uuid)
code
string
ExampleCENTRINIS
displayName
string
ExampleCentrinis sandėlis
contact
string
ExampleVardas Pavarde
addressLine1
string
ExampleSavanorių pr. 1
addressLine2
string
Example
city
string
ExampleVilnius
state
string
Example
country
string
ExampleLT
postalCode
string
ExampleLT-03116
phoneNumber
string
Example+370 5 2000000
email
string (email)
website
string
Example
lastModifiedDateTime
string (date-time)
dimensionSetLines
Array of object (dimensionSetLine)
object

Dimension set line (standard page "APIV2 - Dimension Set Lines"). If the customer, vendor, G/L account or item has default dimensions, overriding them on a document line needs additional PATCH requests; without default dimensions, send the dimensions with the line in the same request. For documents with hundreds of lines, post dimensions in a separate $batch request.

id
string (uuid)

SystemId of the dimension (not of the line)

code
string
ExamplePADALINYS
consolidationCode
string
Example
parentId
string (uuid)
parentType
string
Valid values[ "_x0020_", "Journal_x0020_Line", "Sales_x0020_Order", "Sales_x0020_Order_x0020_Line", "Sales_x0020_Quote", "Sales_x0020_Quote_x0020_Line", "Sales_x0020_Credit_x0020_Memo", "Sales_x0020_Credit_x0020_Memo_x0020_Line", "Sales_x0020_Invoice", "Sales_x0020_Invoice_x0020_Line", "Purchase_x0020_Invoice", "Purchase_x0020_Invoice_x0020_Line", "General_x0020_Ledger_x0020_Entry", "Time_x0020_Registration_x0020_Entry", "Sales_x0020_Shipment", "Sales_x0020_Shipment_x0020_Line", "Purchase_x0020_Receipt", "Purchase_x0020_Receipt_x0020_Line", "Purchase_x0020_Order", "Purchase_x0020_Order_x0020_Line", "Purchase_x0020_Credit_x0020_Memo", "Purchase_x0020_Credit_x0020_Memo_x0020_Line" ]
ExampleSales_x0020_Invoice
displayName
string
ExamplePadalinys
valueId
string (uuid)
valueCode
string
ExampleADM
valueConsolidationCode
string
Example
valueDisplayName
string
ExampleAdministracija
pdfDocument
object (pdfDocument)

PDF of the document (standard page "APIV2 - PDF Document", read-only). Download the file with GET .../pdfDocument/pdfDocumentContent. The report and layout come from Report Selections for the document type; if more than one report is set up, the first in sequence is used.

id
string (uuid)
parentId
string (uuid)
parentType
string
Valid values[ "_x0020_", "Journal", "Sales_x0020_Order", "Sales_x0020_Quote", "Sales_x0020_Credit_x0020_Memo", "Sales_x0020_Invoice", "Purchase_x0020_Invoice", "Purchase_x0020_Order", "Employee", "Job", "Item", "Customer", "Vendor", "Purchase_x0020_Credit_x0020_Memo", "Customer_x0020_Statement" ]
ExampleSales_x0020_Invoice
pdfDocumentContent@odata.mediaReadLink
string (uri)
discountAmount
number
Example0
discountAppliedBeforeTax
boolean
Exampletrue
totalAmountExcludingTax
number
Example500
totalTaxAmount
number
Example105
totalAmountIncludingTax
number
Example605
apiTotalAmountExclVAT
number

Total excluding VAT as calculated by the external system. Compared with the amount calculated by Business Central when Check VAT Mismatch in API Request is enabled.

Example500
apiTotalAmountInclVAT
number

Total including VAT as calculated by the external system. Used for the VAT mismatch check and, when Allow VAT Auto Correction is enabled, to correct VAT differences within Max. VAT Difference Allowed.

Example605
status
string
Valid values[ "_x0020_", "Draft", "In_x0020_Review", "Open", "Paid", "Canceled", "Corrective" ]
ExampleDraft
posted
boolean
locationCode
string
ExampleCENTRINIS
documentLink
string

URL stored as a record link on the document.

Examplehttps://example.com/invoices/KP50055.pdf
documentNote
string

Text stored as a record note on the document.

Example
closed
boolean

Posted invoice is fully applied (closed). Always false for drafts. The page accepts a value but ignores it.

lastModifiedDateTime
string (date-time)
attachments
Array of object (attachment)
object

Incoming document attachment (standard page "APIV2 - Attachments"). Upload or download the file content via .../attachments({id})/attachmentContent.

id
string (uuid)
parentId
string (uuid)
fileName
string
ExampleTest.pdf
byteSize
integer
Example0
attachmentContent@odata.mediaEditLink
string (uri)
attachmentContent@odata.mediaReadLink
string (uri)
lastModifiedDateTime
string (date-time)
parentType
string
Valid values[ "_x0020_", "Journal", "Sales_x0020_Order", "Sales_x0020_Quote", "Sales_x0020_Credit_x0020_Memo", "Sales_x0020_Invoice", "Purchase_x0020_Invoice", "Purchase_x0020_Order", "Employee", "Job", "Item", "Customer", "Vendor", "Purchase_x0020_Credit_x0020_Memo", "Customer_x0020_Statement" ]
ExampleSales_x0020_Invoice
documentAttachments
Array of object (documentAttachment)
object

Document attachment (standard page "APIV2 - Document Attachments"). Upload or download the file content via .../documentAttachments({id})/attachmentContent. When the attachment is created together with the document (e.g. a signed sales contract), the file content is sent in a separate PATCH request.

id
string (uuid)
fileName
string
ExampleTest.pdf
byteSize
integer
Example0
attachmentContent@odata.mediaEditLink
string (uri)
attachmentContent@odata.mediaReadLink
string (uri)
parentType
string
Valid values[ "_x0020_", "Journal", "Sales_x0020_Order", "Sales_x0020_Quote", "Sales_x0020_Credit_x0020_Memo", "Sales_x0020_Invoice", "Purchase_x0020_Invoice", "Purchase_x0020_Order", "Employee", "Job", "Item", "Customer", "Vendor", "Purchase_x0020_Credit_x0020_Memo", "Customer_x0020_Statement" ]
ExampleSales_x0020_Invoice
parentId
string (uuid)
lineNumber
integer
Example0
documentFlowSales
boolean
documentFlowPurchase
boolean
lastModifiedDateTime
string (date-time)
400

Bad Request

Expand All
object
error
object
code
string
ExampleBadRequest
message
string
ExampleThe field Customer No. of table Sales Header contains a value (P9999999) that cannot be found in the related table (Customer). CorrelationId: fc7b9039-73d9-48d2-a9d3-9a8e0f8b91da.
401

Unauthorized

Headers
WWW-Authenticate
string
Expand All
object
error
object
code
string
Default"Unauthorized"
message
string
Default"The credentials provided are incorrect"