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

Community site session details

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

How to generate an invoice pdf on posted sales invoices

(3) ShareShare
ReportReport
Posted on by 12
I did manage to get the pdf from sales invoices this way:
 
 var geturl = $"{url}companies({companyid})/salesInvoices(06921c8c-f891-ef11-8a6b-000d3add059a)/pdfDocument/pdfDocumentContent";
 //read the pdf content as stream into pdf
 var pdf = await httpClient.GetStreamAsync($"{geturl}");
 //save the pdf to a file
 var file = Path.Combine(Path.GetTempPath(), @"c:\temp\test.pdf");
 using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))
 {
     await pdf.CopyToAsync(fileStream);
 }
 
This worked. But when I use the guid from a posted sales invoice coming from table Sales Invoice Header in stead of table Sales Header I always get a 404. 
Copilot suggested using this:
 

GET https://api.businesscentral.dynamics.com/v2.0/{tenantId}/{environment}/api/v2.0/companies({companyid})/postedSalesInvoices({invoiceid})/pdfDocument({invoiceid})/content

But I cannot find documentation on this code, when I ask for a reference, CoPilot says there is no reference, hence he made this up.
 
In the documentation from Microsoft I cannot find a clue on how to get the posted sales invoice pdf. The only way possible I can think of is if the pdf was added as attachment, then I could find it perhaps, but this is not the case for me. I want to generate the invoice like the first call for sales invoices.
 
Is there anybody that has experience getting the pdf invoice document of a posted invoice through the API?
 
Thanks.

 

I have the same question (0)
  • Suggested answer
    Mustafa Omerbegović Profile Picture
    1,457 Super User 2025 Season 2 on at
    How to generate an invoice pdf on posted sales invoices
    Hello,
     
    No functionality will generate a PDF of a posted document that you do not have attached to the posted document.
     
    This post from Yun could give you some ideas on how to deal with this case.
     
    Once the PDF is attached to the posted invoice, you can retrieve it via the attachments endpoint of the postedSalesInvoices API.
     
    Of course that this approach requires custom development, but I am sure that it will make your idea a reality.
     
     
    Greetings
  • YUN ZHU Profile Picture
    92,797 Super User 2025 Season 2 on at
    How to generate an invoice pdf on posted sales invoices
    Hi, This requires customizing new APIs, and hopefully the following information can give you some hints.
    Dynamics 365 Business Central: How to use Standard/Custom API Bound Actions
    Dynamics 365 Business Central: Using OData V4 unbound action (Codeunit API?) to communicate and exchange data seamlessly
     
    Thanks.
    ZHU
  • MD-09050914-0 Profile Picture
    12 on at
    How to generate an invoice pdf on posted sales invoices
    I do think it should be possible, since its possible via the user interface:
     
    This is the exact thing I would like to do.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,285

#2
Sumit Singh Profile Picture

Sumit Singh 2,725

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,526

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans