0

I have gone through the API documentation which is available on https://www.printfriendly.com/api/instructions. But am failed to integrate this ASP.NET Web forms.

The sample code was given there

curl https://api.printfriendly.com/v1/pdfs/create \
  -u your_api_key: \
  -d page_url=https://en.wikipedia.org/wiki/Eclipse

I have changed the code to ajax call

 $.ajax({
            url: 'https://api.printfriendly.com/v1/pdfs/create \\  -u c56bd01d6b5ddwer57ee5ae321f875fd1: \\',
            type: 'GET',
            data: { page_url: pageurl},
            crossDomain: true,

            dataType:"jsonp",// dataType: 'json',
            //headers: {
            //    'Access-Control-Allow-Origin': '*'
            //},
            success: function (data) {
                console.log(data);
                }
            }
        );

and am getting an error while executing this code.

Is there anyone having experience in working with this API. Please help me how can I integrate this into ASP.NET web form.

Reshmy
  • 25
  • 8
  • Sounds like you're missing a header. – gilliduck Jan 31 '18 at 13:20
  • If you control the `api.printfriendly.com` domain you need to add CORS headers to the response coming from the server side. If you have no access to that domain, you cannot make a request to it from JS due to the Same Origin Policy – Rory McCrossan Jan 31 '18 at 13:20
  • @RoryMcCrossan can you help me on this, can you please remove the duplicate label from the question. I made changes to it. – Reshmy Jan 31 '18 at 13:56
  • The edit doesn't change the problem. You need to add CORS headers to the response. If you do not have access to the API code, which I'm guessing you don't as it's a public service, then you will not be able to call it from JS. You will need to make the request server-side. – Rory McCrossan Jan 31 '18 at 13:59

0 Answers0