Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

SalesInvoiceLines not being created when using the API

Posted on by 2
Hello,
 
I have been using the Business Central API now for 2.5 years.  I built an application to sync our on-premise inventory system with Business Central.  These POST API calls work fine and they have not changed since I implemented the application: customers, item categories, and items.
 
When I built the application, I used the SalesOrders endpoint and was able to submit the following JSON and it would create the Sales Order with the Sales Order Lines.
 
{    /customerId/: /{{customerId}}/,    /externalDocumentNumber/: /{{orderId}}/,    /salesperson/: /{{SalesPerson}}/,    /shippingPostalAddress/: {        /street/: /{{address1}}/,        /city/: /{{city}}/,        /state/: /{{state}}/,        /countryLetterCode/: /{{country}}/,        /postalCode/: /{{postcode}}/    },    /salesOrderLines/: [        {            /sequence/: 10000,            /itemId/: /{{line1_itemId}}/,            /quantity/: {{line1_qty}},            /shipmentDate/: /{{shipDate}}/        },        {            /sequence/: 20000,            /itemId/: /{{line2_itemId}}/,            /quantity/: {{line2_qty}},            /shipmentDate/: /{{shipDate}}/        }    ]}
 
About 6 months ago, the API started erroring and I found that the SalesOrders endpoint no longer accepted the salesOrderLines property/array.  I needed to switch the application and make multiple posts requests to the /salesInvoices({{invoice_id}})/salesInvoiceLines endpoint to get the line items to show up.
 
Sales Invoice
{    /customerId/: /{{customerId}}/,    /externalDocumentNumber/: /{{orderId}}/,    /salesperson/: /{{SalesPerson}}/,    /shippingPostalAddress/: {        /street/: /{{address1}}/,        /city/: /{{city}}/,        /state/: /{{state}}/,        /countryLetterCode/: /{{country}}/,        /postalCode/: /{{postcode}}/    }}
Sales Invoice Line 1
 
        {            /sequence/: 10000,            /itemId/: /{{line1_itemId}}/,            /quantity/: {{line1_qty}},            /shipmentDate/: /{{shipDate}}/        }
 
 
Sales Invoice Line 2
 
        {            /sequence/: 20000,            /itemId/: /{{line2_itemId}}/,            /quantity/: {{line2_qty}},            /shipmentDate/: /{{shipDate}}/        }
 
Now the sync application is intermittently failing to create the Sales Invoice Lines for a given invoice.  I looked through all of the Microsoft Business Central documentation for the Sales Invoice APIs and found that it is the same request that I am sending.  But I am getting a 400 Bad Request error.
 
I have tried both of the URLs found here: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_salesinvoiceline_create and neither work.   Both return the 400 Bad Request error.
I cannot seem to find an updated schema maps or change history notes for why the endpoints would just stop working for the Sales Invoice Lines.  I am not submitting anything fancy, just the itemId, quantity, and unitPrice.
 
This is causing a lot of delay in the accounting department.  Any help would be appreciated.
 
Thanks,
Travis
  • SalesInvoiceLines not being created when using the API
    Hi Yun Zhu,
     
    I am use Postman to figure out and troubleshoot the API endpoint and request related issues.  I use the RestSharp or HttpClient libraries to make the API calls from within C# application.  I have used Visual Studio to debug the code, but all I get is a 400 Bad Request error from both Postman and the C# in debug mode.  So I am not sure what is wrong with the request or where to start looking for a more detailed error message.  Did the endpoint change recently and the documentation has not been updated?
     
    Thanks,
    Travis
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,664 Super User 2024 Season 2 on at
    SalesInvoiceLines not being created when using the API
    Hi, is this a problem when posting in Postman? It seems to be a code problem.
    In addition, please confirm the API version you are using, beta, 1.0 or 2.0. Please try to use 2.0.
     
     
    If you still can't find the cause, it is recommended to submit an SR to the Microsoft support team for them to assist in the investigation.
     
     
    Hope this helps.
    Thanks.
    ZHU

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,339 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans