Create Sales Invoice

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

Creates a draft sales invoice. Either customerNumber or customerId must be provided. You can include salesInvoiceLines in the body (deep insert). Use $expand=salesInvoiceLines to have the created lines included in the response. invoiceDate, postingDate and dueDate are applied after the customer is validated, so the values sent are kept. 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 sales invoices. Supported navigations: salesInvoiceLines, dimensionSetLines, pdfDocument, attachments, documentAttachments. Line navigations can be nested, e.g. salesInvoiceLines($expand=dimensionSetLines,location).

ExamplesalesInvoiceLines,dimensionSetLines
Body parameters
headerOnly

Header-only invoice

{
  "invoiceDate": "2022-11-21",
  "postingDate": "2022-11-21",
  "dueDate": "2023-02-19",
  "customerPurchaseOrderReference": "NOTARINĖS SUT NR.",
  "customerNumber": "P00004",
  "billToCustomerNumber": "P00004",
  "shipToName": "Antanas Antanaitis",
  "currencyCode": "EUR",
  "salesperson": "AT"
}
withApiTotals

Header with external VAT totals

{
  "invoiceDate": "2026-03-21",
  "postingDate": "2026-03-21",
  "dueDate": "2026-04-05",
  "customerNumber": "P0000004",
  "billToCustomerNumber": "P0000004",
  "currencyCode": "EUR",
  "salesperson": "PIRMAS",
  "paymentMethodCode": "PAVEDIMU",
  "locationCode": "CENTRINIS",
  "apiTotalAmountExclVAT": 100,
  "apiTotalAmountInclVAT": 121
}
withLines

Invoice with lines (+$expand)

{
  "externalDocumentNumber": "TEST001",
  "invoiceDate": "2020-10-22",
  "postingDate": "2020-10-22",
  "dueDate": "2020-11-01",
  "customerNumber": "P0000001",
  "billToCustomerNumber": "P0000001",
  "currencyCode": "EUR",
  "salesperson": "PJ",
  "shortcutDimension1Code": "PARD",
  "shortcutDimension2Code": "444",
  "salesInvoiceLines": [
    {
      "lineType": "Item",
      "lineObjectNumber": "Z0000001",
      "locationCode": "CENTRINIS",
      "description": "Kėdė baro",
      "unitOfMeasureCode": "VNT",
      "unitPrice": 100,
      "quantity": 20,
      "taxCode": "A PREK21",
      "shipmentDate": "2020-10-22"
    },
    {
      "lineType": "Item",
      "lineObjectNumber": "Z0000002",
      "locationCode": "CENTRINIS",
      "description": "Stalas baro",
      "unitOfMeasureCode": "VNT",
      "unitPrice": 150,
      "quantity": 20,
      "taxCode": "A PREK21",
      "shipmentDate": "2020-10-22"
    }
  ]
}
Expand All
object

Payload to create or update a sales invoice. On create either customerId or customerNumber must be provided. salesInvoiceLines can be included on create (deep insert). The fields postingDescription, shortcutDimension1Code, shortcutDimension2Code, paymentMethodCode, locationCode, userId, apiTotalAmountExclVAT and apiTotalAmountInclVAT are applied only when they are not empty (not zero), so they cannot be cleared through the API. documentLink and documentNote add a record link and a record note to the document.

externalDocumentNumber
string
Max length35
Example001
invoiceDate
string (date)
Example2023-04-02
postingDate
string (date)
Example2023-04-02
dueDate
string (date)
Example2023-04-16
customerPurchaseOrderReference
string
Max length35
Example
postingDescription
string
ExampleDalinis apmokėjimas SF, Užsakymas SO0000059.
customerId
string (uuid)
customerNumber
string
Max length20
ExampleP0000048
billToCustomerId
string (uuid)
billToCustomerNumber
string
Max length20
ExampleP0000048
shipToName
string
Max length100
ExampleRelecloud
shipToContact
string
Max length100
ExampleJesse Homer
sellToAddressLine1
string
Example
sellToAddressLine2
string
Example
sellToCity
string
Max length30
ExampleVilnius
sellToCountry
string
Max length10
ExampleLT
sellToState
string
Max length30
Example
sellToPostCode
string
Max length20
Example
shipToAddressLine1
string
Example
shipToAddressLine2
string
Example
shipToCity
string
Max length30
ExampleVilnius
shipToCountry
string
Max length10
ExampleLT
shipToState
string
Max length30
Example
shipToPostCode
string
Max length20
Example
currencyId
string (uuid)
shortcutDimension1Code
string
ExamplePARD
shortcutDimension2Code
string
Example333
currencyCode
string
ExampleEUR
paymentTermsId
string (uuid)
paymentMethodCode
string
ExamplePAVEDIMU
shipmentMethodId
string (uuid)
salesperson
string
Max length20
ExamplePJ
discountAmount
number
Example0
phoneNumber
string
Max length30
Example+370 37 777777
email
string (email)
Max length80
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.

Example2000
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.

Example2420
locationCode
string
ExampleCENTRINIS
userId
string
ExampleJONAS
documentLink
string
Examplehttps://example.com/documents/SIP00000001
documentNote
string
Example
salesInvoiceLines
Array of object (salesInvoiceLineRequest)

Deep insert of lines (create only).

object

Payload to create or update a sales invoice line. Lines can only be changed on draft invoices. documentId is required when the line is created through the root salesInvoiceLines endpoint. shortcutDimension1Code and shortcutDimension2Code are applied only when not empty.

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
quantity
number
Example20
unitPrice
number
Example100.1234
discountAmount
number
Example0
discountPercent
number
Example0
taxCode
string
Max length50
ExampleA PREK21
shipmentDate
string (date)
Example2025-03-22
itemVariantId
string (uuid)
shortcutDimension1Code
string
ExamplePARD
shortcutDimension2Code
string
Example333
Responses
201

Created

Headers
Location
string (uri)
URL of the created invoice
Expand All
object

Sales invoice, draft or posted. A draft invoice is a Sales Header with document type Invoice, a posted invoice is a Sales Invoice Header. Use posted and status to tell them apart.

id
string (uuid)
number
string
Max length20
ExampleSIP00000001
externalDocumentNumber
string
Max length35
Example001
invoiceDate
string (date)
Example2023-04-02
postingDate
string (date)
Example2023-04-02
dueDate
string (date)
Example2023-04-16
customerPurchaseOrderReference
string
Max length35
Example
postingDescription
string
ExampleDalinis apmokėjimas SF, Užsakymas SO0000059.
customerId
string (uuid)

Sell-to customer SystemId. Either customerId or customerNumber is required on create.

customerNumber
string

Sell-to customer number. Either customerId or customerNumber is required on create.

Max length20
ExampleP0000048
customerName
string
Max length100
ExampleSoftera Baltic, UAB
billToName
string
Max length100
Example
billToCustomerId
string (uuid)
billToCustomerNumber
string
Max length20
Example
shipToName
string
Max length100
ExampleRelecloud
shipToContact
string
Max length100
ExampleJesse Homer
sellToAddressLine1
string
Example
sellToAddressLine2
string
Example
sellToCity
string
Max length30
ExampleLondon
sellToCountry
string
Max length10
ExampleGB
sellToState
string
Max length30
Example
sellToPostCode
string
Max length20
Example
billToAddressLine1
string
Example
billToAddressLine2
string
Example
billToCity
string
Max length30
ExampleVilnius
billToCountry
string
Max length10
ExampleLT
billToState
string
Max length30
Example
billToPostCode
string
Max length20
Example
shipToAddressLine1
string
Example
shipToAddressLine2
string
Example
shipToCity
string
Max length30
ExampleLondon
shipToCountry
string
Max length10
ExampleGB
shipToState
string
Max length30
Example
shipToPostCode
string
Max length20
Example
currencyId
string (uuid)
shortcutDimension1Code
string
ExamplePARD
shortcutDimension2Code
string
Example333
currencyCode
string
ExampleEUR
orderId
string (uuid)
orderNumber
string
Max length20
Example
paymentTermsId
string (uuid)
paymentMethodCode
string
ExamplePAVEDIMU
shipmentMethodId
string (uuid)
salesperson
string
Max length20
ExamplePJ
pricesIncludeTax
boolean
remainingAmount
number

Draft: amount including VAT. Posted: remaining amount of the invoice. Canceled: 0.

Example2420
discountAmount
number
Example0
discountAppliedBeforeTax
boolean
totalAmountExcludingTax
number
Example2000
totalTaxAmount
number
Example420
totalAmountIncludingTax
number
Example2420
status
string
Valid values[ "_x0020_", "Draft", "In_x0020_Review", "Open", "Paid", "Canceled", "Corrective" ]
ExampleDraft
posted
boolean
lastModifiedDateTime
string (date-time)
phoneNumber
string
Max length30
Example+370 37 777777
email
string (email)
Max length80
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.

Example2000
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.

Example2420
locationCode
string
ExampleCENTRINIS
userId
string

Assigned User ID of the document.

ExampleJONAS
documentLink
string

URL stored as a record link on the document.

Examplehttps://example.com/documents/SIP00000001
documentNote
string

Text stored as a record note on the document.

Example
closed
boolean

Posted invoice is fully applied (closed). Always false for drafts.

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
salesInvoiceLines
Array of object (salesInvoiceLine)
object
id
string (uuid)
documentId
string (uuid)

SystemId of the sales invoice. Cannot be changed.

sequence
integer

Line No. Cannot be changed, delete and insert the line again.

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

Item or G/L account number, depending on lineType. Cannot be changed once set.

Max length20
ExampleZ0000001
locationCode
string
Max length10
ExampleCENTRINIS
description
string
Max length100
ExampleSulankstoma kėdė
unitOfMeasureId
string (uuid)
unitOfMeasureCode
string
Max length10
ExampleVNT
quantity
number
Example20
unitPrice
number
Example100.1234
discountAmount
number
Example0
discountPercent
number
Example0
discountAppliedBeforeTax
boolean
amountExcludingTax
number
taxCode
string
Max length50
ExampleA PREK21
taxPercent
number
Example21
totalTaxAmount
number
amountIncludingTax
number
invoiceDiscountAllocation
number
netAmount
number
netTaxAmount
number
netAmountIncludingTax
number
shipmentDate
string (date)
Example2025-03-22
itemVariantId
string (uuid)
shortcutDimension1Code
string
ExamplePARD
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)
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)
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"