PDF create api catch and save file using server connect

Sorry if my terms aren’t correct going into this. I want to call an api with server connect. This api uses an url with dynamic id I supply it using a previous step in server connect action. It looks like this:

https://v2018.api2pdf.com/chrome/url?url={UrlToConvert}&apikey={YourApiKey}

By typing it into my browser with the params filled it works perfectly and file downloads in browser

Is there a way to use curl to “catch” this file with server connect and save it to a folder + save the filename.

Documentation for api is here: https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/1.0.0

This looks like the response I should get:

15

Hi Marcel,

Similar request by me here:

in case you want to track that thread as well.

–Ken

thanks @mebeingken!

api2pdf returns json when the Accept headers are set to application/json. It then returns in a format like:

{
  "pdf": "https://link-to-your-pdf",
  "mbIn": 0.06463,
  "mbOut": 0.73327,
  "cost": 0.0007979,
  "success": true,
  "responseId": "0cdfdb27-dcc0-413e-a713-b9371b2e2678"
}

The pdf link can be used for 24 hours before it is deleted.

Actually just got this working :slight_smile: yay!

Call via server connect API and add link to mail for user. They click and it downloads.

I am trying to do exactly the same thing with api2pdf. Honestly, I tried this about a year ago and gave up. Now trying to solve this again as I see that you did. I can get the api2pdf to work directly in a browser with the get request, but I need it to work within a webpage using their post request. I can’t get this to work at all and I see that wappler is supposed to be able to do this with their api connector which honestly I have no idea how it works.
I have a file which has a button linke to a server connect file which tries to connect to api2pdf but nothing happens. Can you help guide me please?
Thanks, Rick

Here is the code for the server connect file which tries to use api connector

<?php require('../../dmxConnectLib/dmxConnect.php'); $app = new \lib\App(); $app->define(<

Looking for help in getting this pdf creator api to work within wappler. Just trying to convert urls to pdfs and download them assigning filenames from the data. The api2pdf site gives a lot of examples and the simple ones work if pasted directly into a browser. However, trying to use more advance versions to assign filenames require more knowledge about json then I have. I’ve tried to follow some of the previous posts as people have done this exact same thing but just stuck and wappler documentation is too generic on this at this point. Any help or guidance would really be appreciated.

Rick

Here is my server connect steps to eventually generate and email with the url to download the pdf:

Screenshot 2020-04-22 at 16.16.53

The first section is irrelevant to your needs.

This is my API action step:

This is example of the Json params I send to api2pdf which points to the page I want converted:

{ "url": "http://westbrookeform.dryrun.co.za/document.html?id={{query1.unique}}", "output": "json", "options": { "marginLeft": 0, "marginTop": 0, "marginRight": 0, "marginBottom": 0 } }

Hope this help you on your way

thanks. looking at your server connect code, it’s pretty close to what I want to do. I tried to set up the api connector and even put in the set value of the data.pdf response to mail to myself.
When I run the code with debugging, I get the following:

file: “/home/marsscom/public_html/dmxConnectLib/modules/api.php”
3. line: 158
4. message: “Call to undefined function modules\curl_init()”

I’m just trying to convert the google.com home page to a pdf to test so there is nothing crazy here.

Also compared mine with yours and cannot see any differences. It sometimes helps starting with a “clean” server connect file instead of editing and re-editing an existing trying to find the right config.

Hi Pixlapps

Ok all OK but it does not print the {{dynamic data}} it prints all the static info.
If i look at the page on the internet via a browser… i can see the data rendered.
But once i make the “API” request … then it only prints out the Static text and not the {{serverconnect data}}

Is there a function to make the DOM load fully before it runs the script…
As i cant get the data on the url the print :frowning: :frowning: but it shows in the browser… eish

I have not come accros this. Something like a seperate stylesheet could be the issue… but that is a longshot. Hope one of the more experienced support guys can give you some pointers.

Hi Marcel… thanks for the response :wink: i found the problem. Because we are loading the data with serverconnect / javascript… it takes time to load… so the solution … add a delay to the snapshot … …

So if you wish to load dynamic data … and you want to print it with api2pdf … remember to add the delay to your script …

‘options’: {
‘delay’: 3000
}

1 Like