web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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,965

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?

I have the same question (0)
  • keoma Profile Picture
    32,729 on at

    via web service or al?

  • Babin Profile Picture
    2,965 on at

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

  • keoma Profile Picture
    32,729 on at

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

  • Babin Profile Picture
    2,965 on at

    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?

  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,608 on at

    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

  • Lars Lohndorf-Larsen Profile Picture
    Microsoft Employee on at

    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?

  • Lars Lohndorf-Larsen Profile Picture
    Microsoft Employee on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,958 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,101 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans