Monday 18 May 2020

Retrieve Business Central Report Print-out Using API - Get pdfDocument


Hello folks today I'm going to introduce you one very cool Business Central API that will help you to get the Report PDF file in binary format and use it in further business process.

HTTP Request for the pdfDocument is:

GET https://api.businesscentral.dynamics.com/v2.0/{Business Central Tenant ID}/{Sandbox Environment Name}/api/v1.0/companies({ID})/salesInvoices(ID)/pdfDocument

for request Headers you would pass the Authorization as per your Business Central User.

Not only that, we can generate the Report in Any preferred language you must specify Accept-Language in the Request header, for example Accept-Language: nl-NL for Dutch

Now I'll show you how to get the dynamic parameters of this API.

1) {Business Central Tenant ID}: You can get Tenant Id by simply login to Admin Center. select the Sendbox/Production environment.

In the Tenant URL you can find the Tenant ID. 

Business Central Admin Center - URL

2){Companies ID}: Each Company in your tenant have one unique GUID key associated with it as shown in below screenshot.

Company ID

Other Way of getting all companies Information is that use Get API for Company. As shown below we can use this API in Postman and get required details.


https://api.businesscentral.dynamics.com/v2.0/df4c3c4d-297f-4f04-92e3-617e98144580/geeky/api/v1.0/companies

3){salesInvoices(ID)}: Here we are taking Sales Invoice Example. Documents have unique GUID field attached to it as per the below screenshot we use that GUID as a Sales Invoice ID. 

SalesInvoice ID

If the successful call , this method returns a 200 OK response code and a link to the PDF document in the response body.

HTTP Response for the pdfDocument is:

Response of successful API call is shown below. from this response we got the Sales Invoice Report PDF Content file.

The "content@odata.mediaReadLink" in the response contains the Link that have PDF Data in Binary form.

Response Details

By clinking this Link we get the Report PDF file in Binary form.....Gotcha..Its so easy isn't it.

PDF Report Output in Binary




Hope you like this Blog. Give me your thoughts about the same in Comment Box below. Also Follow me on Social Media Platforms for content like this.


In the Next Blog I'll show you guys how to use this API to create a cool Microsoft Power Automate Integration till then stay tuned.

LinkedIn :  Preet Gor




8 comments:

  1. Very nicely explained.👍🏻

    ReplyDelete
  2. I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you... https://newsweek.top/

    ReplyDelete
  3. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article. News Update

    ReplyDelete
  4. I would like to say that this blog really convinced me to do it! Thanks, very good post. Abu Dhabi Business Registration

    ReplyDelete
  5. Please continue this great work and I look forward to more of your awesome blog posts. Abu Dhabi Business Registration

    ReplyDelete