Skip to main content
Solved

How to return a pdf report via the API


Harm Horstman
Superhero
Forum|alt.badge.img+21

We are looking for a way to make a pdf report, based on real time data, available on the customer's website. The intention is not to show the report in an iframe, but as a download.

Something like how the file API works would be great, but then a real time generated file as response.

Is there a way to realize this with a GET request?
example: https://.../indicium/iam/api/public_vessel_schedule_pdf?route_name=north_europe&duration_weeks=4

Or will this always have to be done via a POST request?

We have started setting up a system flow, but we are stuck.

What is the recommended approach?

Best answer by Peter Verwijs

Hi Harm,

You should be able to do this with a custom protocol process flow. You can use a GET request to call this process flow and use it to return the binary data of the report. There’s some more information and examples available here: 


The response header should look something like this:
Content-Type: application/json

Content-Disposition: attachment; filename="xyz.pdf"

A varbinary process variable should be assigned to the response body
 

You can then assign the output parameter of the Generate report process action to the response_body variable.

Calling the process flow should look something like this:
GET

/indicium/open/iam/appl/my_process_flow

View original
Did this topic help you find an answer to your question?

5 replies

Peter Verwijs
Moderator
Forum|alt.badge.img+2

Hi Harm,

You should be able to do this with a custom protocol process flow. You can use a GET request to call this process flow and use it to return the binary data of the report. There’s some more information and examples available here: 


The response header should look something like this:
Content-Type: application/json

Content-Disposition: attachment; filename="xyz.pdf"

A varbinary process variable should be assigned to the response body
 

You can then assign the output parameter of the Generate report process action to the response_body variable.

Calling the process flow should look something like this:
GET

/indicium/open/iam/appl/my_process_flow


Harm Horstman
Superhero
Forum|alt.badge.img+21

Thank you ​@Peter Verwijs ,

I will try this.

 


Harm Horstman
Superhero
Forum|alt.badge.img+21

I have tried this and found out that a custom protocol process flow works for both POST and GET requests. 

 


Harm Horstman
Superhero
Forum|alt.badge.img+21

@Peter Verwijs ,

It works almost perfect, but I still have problems with the response header.

I am not sure how to combine Content-Type and Content-Disposition. 

Do you have a working example?

 

 


Harm Horstman
Superhero
Forum|alt.badge.img+21

It took a while, but I finally found the solution for composing valid response headers in SQL Server

output pdf as download:

SET @response_headers = '{"Content-Type": ["application/pdf"], "Content-Disposition": ["attachment; filename=\"response.pdf\""]}' 

output xlsx as download:

SET @response_headers = '{"Content-Type": ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], "Content-Disposition": ["attachment; filename=\"response.xlsx\""]}' 


 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings