Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Create purchaseInvoices and purchaseInvoiceLines

(0) ShareShare
ReportReport
Posted on by 2,961

I am trying to create Purchase Invoice and Lines together with single call. Is this possible? Can we use "Expand" functionality for this to create Invoice and lines together?

  • Lars Lohndorf-Larsen Profile Picture
    on at
    RE: Create purchaseInvoices and purchaseInvoiceLines

    To answer some of my own question: I found a syntax that works:

    docs.microsoft.com/.../dynamics_create_purchaseinvoiceline

    POST businesscentralPrefix/companies({id})/purchaseInvoices({id})/purchaseInvoiceLines

    But in Flow we can only pick from the standard list:

    pastedimage1581000062873v1.png

    Or maybe somehow in Flow we can also use the same syntax? I a'm new to Flow. So basically - any ideas how to do this through Flow?

    Lars

  • Lars Lohndorf-Larsen Profile Picture
    on at
    RE: Create purchaseInvoices and purchaseInvoiceLines

    How to do it one line at the time, without the header? Here, I already have a Purchase Invoice, but only want to add a line. With this:

    POST {{BaseURL}}/companies(177114a9-621d-ea11-bb2d-000d3a257ac8)/purchaseInvoiceLines

    {
    "accountId": "74eecaeb-621d-ea11-bb2d-000d3a257ac8",
    "documentId": "5daf9442-d748-ea11-a812-000d3a722b1a"
    }

    I get this error:

    Application_DialogException  The value for documentId cannot be modified.

    If I leave documentId empty I get an error that it must be specified... Any ideas to how to just insert a purchase line?

  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,594 on at
    RE: Create purchaseInvoices and purchaseInvoiceLines

    To create no need to use expand, Expand is used to retrieve . What matters is your JSON body must specify the line as well , below sample JSON to create header and line in single call.

    {
       "vendorInvoiceNumber":"",
       "invoiceDate":"2018-12-25",
       "dueDate":"2018-12-25",
       "vendorNumber":"10000",
       "purchaseInvoiceLines" :
       [
    	{
    	   "sequence":10000,
    	   "lineType":"Item",
    	   "itemId": "715f88b5-c1df-e911-bb22-000d3ab0ebc8",
    	   "description":"12 GG INTERNATIONAL",
    	   "directUnitCost":20000,
    	   "quantity":10,
          	   "unitOfMeasure": {
              	  "code": "PCS",
                	"displayName": "Piece",
                	"symbol": null,
                	"unitConversion": null
               }
    	},
    	{
    	   "sequence":20000,
    	   "lineType":"Item",
    	   "itemId": "715f88b5-c1df-e911-bb22-000d3ab0ebc8",
    	   "description":"ES TEH MANIS",
    	   "directUnitCost":5000,
    	   "quantity":5,
               "unitOfMeasure": {
                	"code": "PCS",
                	"displayName": "Piece",
                	"symbol": null,
                	"unitConversion": null
                }
    	}
       ]
    }

    You can also check my blog post : 

    https://madearipermadi.com/2019/12/19/postman-collection-to-explore-business-central-api/

    it has sample in Postman collection

  • Babin Profile Picture
    2,961 on at
    RE: Create purchaseInvoices and purchaseInvoiceLines

    Yes C# but I am trying to test this from Postman first.

    I am trying to create an Invoice with POST Method combining $expand parameter like this to create the Purchase Invoice and Lines together:

    POST https://{businesscentralPrefix}/api/v1.0/companies({id})/purchaseInvoices?$expand=purchaseInvoiceLines

    Can this be used to create Purchase Invoice and Lines together? In my case, its not accepting the Purchase Lines. Any Idea why its not accepting the PurchaseInvoicelines?

  • keoma Profile Picture
    32,727 on at
    RE: Create purchaseInvoices and purchaseInvoiceLines

    whats your code, which calls the webservice? c#?

  • Babin Profile Picture
    2,961 on at
    RE: Create purchaseInvoices and purchaseInvoiceLines

    sorry should have been mentioned this earlier. I am trying to create Purchase Invoices/InvoiceLines via Web Service.

  • keoma Profile Picture
    32,727 on at
    RE: Create purchaseInvoices and purchaseInvoiceLines

    via web service or al?

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 944

#2
YUN ZHU Profile Picture

YUN ZHU 848 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 602

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans