Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Business Central API salesInvoices issue

Posted on by 134

Hi everyone,

I'm new in field of API in business central. 

Scenerio:- I'm using standard API of business central "salesInvoices" 

GET Call = https://api.businesscentral.dynamics.com/v2.0/(my tenant id)/(my sandbox)/api/v2.0/companies(my company id)/salesInvoices

It returns me all Posted and non-Posted Sales Invoices, BUT

there is a field with name "Status", it tells us the status of invoice

pastedimage1679417681547v1.png

pastedimage1679417745089v2.png

my question is how can we differentiate between Posted and non-Posted sales Invoice because Open status can be for both Posted and non-Posted invoices? 

Thanks for your consideration

Categories:
  • Abdullah Khalid Profile Picture
    Abdullah Khalid 134 on at
    RE: Business Central API salesInvoices issue

    Yes YUN ZHU thanks for your reply, and yes Custom API is only solution for this scenario

    I created custom API of Standard Table "Sales Invoice Entity Aggregate"  and there is a field "isPosted" I added that field in my custom API page so we can use it to differentiate between Posted and Non-Posted  invoice of Status "OPEN".

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    RE: Business Central API salesInvoices issue

    Hi, Daniele, the IsPosted field does not exist for this standard API. I hope you can make sure when answering the question.

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/resources/dynamics_salesinvoice#properties

    Hi, Abdullah. I think you have investigated, this standard API, the source table is "Sales Invoice Entity Aggregate". It contains not only "Sales Header" but also "Sales Invoice Header". And as far as I know, we can't use the Status field to distinguish them.

    pastedimage1679442543118v1.png

    The only way I can think of so far is to filter by "number", but that's not guaranteed to be 100% accurate. So I suggest that you customize your own API would be better.

    Hope this helps.

    Thanks.

    ZHU

  • Abdullah Khalid Profile Picture
    Abdullah Khalid 134 on at
    RE: Business Central API salesInvoices issue

               "id": "81b1b0d4-6bec-ea11-bb47-000d3a4927ba",

               "number": "103001",

               "externalDocumentNumber": "",

               "invoiceDate": "2019-01-15",

               "postingDate": "2019-01-15",

               "dueDate": "2019-01-15",

               "customerPurchaseOrderReference": "",

               "customerId": "81b1b0d4-6bec-ea11-bb47-000d3a4927ba",

               "customerNumber": "20000",

               "customerName": "changed by me for security",

               "billToName": "changed by me for security",

               "billToCustomerId": "81b1b0d4-6bec-ea11-bb47-000d3a4927ba",

               "billToCustomerNumber": "20000",

               "shipToName": "changed by me for security",

               "shipToContact": "changed by me for security",

               "sellToAddressLine1": "changed by me for security",

               "sellToAddressLine2": "",

               "sellToCity": "changed by me for security",

               "sellToCountry": "changed by me for security",

               "sellToState": "",

               "sellToPostCode": "4300",

               "billToAddressLine1": "changed by me for security",

               "billToAddressLine2": "",

               "billToCity": "changed by me for security",

               "billToCountry": "changed by me for security",

               "billToState": "",

               "billToPostCode": "4300",

               "shipToAddressLine1": "Parkvej 44",

               "shipToAddressLine2": "",

               "shipToCity": "changed by me for security",

               "shipToCountry": "changed by me for security",

               "shipToState": "",

               "shipToPostCode": "4300",

               "currencyId": "00000000-0000-0000-0000-000000000000",

               "shortcutDimension1Code": "",

               "shortcutDimension2Code": "",

               "currencyCode": "DKK",

               "orderId": "00000000-0000-0000-0000-000000000000",

               "orderNumber": "",

               "paymentTermsId": "deadb0d4-6bec-ea11-bb47-000d3a4927ba",

               "shipmentMethodId": "00000000-0000-0000-0000-000000000000",

               "salesperson": "changed by me for security",

               "pricesIncludeTax": false,

               "remainingAmount": 0,

               "discountAmount": 0,

               "discountAppliedBeforeTax": true,

               "totalAmountExcludingTax": 915,

               "totalTaxAmount": 228.75,

               "totalAmountIncludingTax": 1143.75,

               "status": "Paid",

               "lastModifiedDateTime": "2023-03-21T09:46:17.653Z",

               "phoneNumber": "",

               "email": "changed by me for security",

    This is my response message.

    I can't see that boolean field in my response.

    Can you please tell me little bit more about that?

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: Business Central API salesInvoices issue

    hi

    Regarding your scenario, you are correct that the "Status" field alone cannot be used to differentiate between posted and non-posted invoices, as both posted and non-posted invoices can have an "Open" status.

    However, the API provides other fields that can be used to identify whether an invoice is posted or not. One such field is the "IsPosted" field, which is a Boolean field that indicates whether an invoice has been posted or not. You can use this field to filter and retrieve only posted or non-posted invoices.

    To answer your question, it is not necessary to have separate entities for posted and non-posted invoices, as the API provides fields that allow you to distinguish between them. Instead, you can filter and retrieve only the invoices that meet your criteria using the available fields.

    I hope this helps! Let me know if you have any further questions.

    DAniele

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans