API and parsing of data -api2pdf

Hi, hoping someone can help, I’m using API for the first time specifically api2pdf and am using the headless chrome url to pdf function.

  • I’ve managed to create a pdf but i cant seem to be able to programmatically get the link to where the pdf file is that can be downloaded.
  • Using the dev tools i can see the url, can copy it and run in a browser and download the pdf.
  • Strangely i am able to select the data element FileUrl as part of the page design but it doesnt show in the dev tools data or the resulting text area which i expected to show the url link but is blank.

I have screenshots for all the above.

im using wappler 4.1.3, nodejs, heroku.

I’m not sure if this is a bug or something i’m doing wrong and hope someone can point me in the right direction.

regards

Nigel

It’s been a long time since I used api2pdf, but here’s what I see:

The data element returned here is a string, rather than an object. That is why you can’t access its child element FileUrl.

The url you want is inside there, but it is not in the proper format.

You can see mine here with an older version of the api:

Screen Shot 2021-10-20 at 7.47.41 AM

https://v2018.api2pdf.com/chrome/url

You might try the older version if for nothing else than to troubleshoot.

My JSON body is also much simpler, so maybe one of your settings is causing trouble?

{
  "fileName": "Balance Sheet - {{$_GET.rpt_title}}",
  "url": "https://{{$_SERVER['HTTP_HOST']}}/bs-pdf.php?instance={{$_SESSION.instance}}&end_date={{$_GET.end_date}}&report_title={{$_GET.rpt_title}}",
  "options": {
    "delay": 5000
  }
}

If you are then still stuck, you could probably use a set value and parseJSON() on the data response. Something like:

Url2Pdf.data.parseJSON()

Or if the api is really sending a string, ask the vendor why.

Hi Ken,

Thank you so much, I really appreciate your time and insight.

Given me some great things to explore and try.

Best Regards,

Nigel

Hi Ken, FYI it worked with the older version…have messaged api2pdf… many thanks Nigel

1 Like

Hello Did you manage to display the results returned from the API?
Could you share me the configuration that works with api2pdf, I can’t get the answer to display it

thanks in advance

Hi Morgan,

Unfortunately I couldn’t get to work, so have temporary given up – my temp solution is to create the report as a web page then give guidance on how someone can use the browser and the print option to print to a pdf…. But I do need to find a long term solution at some point.

Sorry I cant be more helpful,

Goodluck,

Nigel

I just managed to retrieve the answer in which the link appears, as soon as I have isolated it by cutting the chain I will send you the configuration

Many thanks Morgan

in the page
add serverconnect
create a variable

and i create a link for download PDF
{{serverconnect1.lastError.response.split(’,’)[29].replace(‘Content-Disposition":"inline; filename=’, ‘https://storage.googleapis.com/a2p-v2-storage/’).replace(’.pdf’,’’).replace(’"’,’’)}}

everything starts when i click the button
Button