Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Authentication methods to export single page to PDF from script

Eugenio Rustico May 14, 2018

Hi,

I need to export a single page to PDF from a script. As far as I understand, the options are:

  1. Use an external plugin for PDF export (such as Scroll PDF) and its API
  2. Use the Confluence CLI interface
  3. Get the URL with a the web browser (e.g. https://.../confluence/spaces/flyingpdf/pdfpageexport.action?pageId=12345678) and use e.g. curl

I would like to use option 3. According to the docs I can use either Basic authentication, which means hardcoding user credentials in a script, or OAuth, which requires a token. I would be happier about OAuth, but from the admin panel it looks like I can generate tokens only for apps/plugins; therefore I must use some user credentials in the scripts, which looks unsafe and cumbersome.

Is there any other way to export a PDF without additional plugins and without using user credentials? Is there any way to generate a token for a script?

Thank you.

1 answer

1 accepted

1 vote
Answer accepted
Eugenio Rustico May 25, 2018

In case someone else is interested: yes, it is possible. The "app URL" can be an arbitrary "virtual" URL and the authentication process can be triggered by command line (the sample clients will provide a link to authenticate a token via browser once).

Elwyn Chow November 11, 2018

How did you get it to work?

 

I can get the Chrome to visit https://domain_name/rest/api/content/38699012

 

When I run curl:

curl -u user_id:password "https://domain_name/spaces/flyingpdf/pdfexport.action?pageId=38699012"

I get a Page Not Found HTML document.

Eugenio Rustico November 12, 2018

Hi,

it should work with the same link used in the browser (e.g. inspecting "download to PDF" item). In my case:

"https://domain/confluence/spaces/flyingpdf/pdfpageexport.action?pageId=$pageId"

Elwyn Chow November 12, 2018

I'm not sure why but Postman handles those sorts of URLs while curl didn't. I also tried Postman's feature that exports the code to run it in curl.

 

I found that solution #2 of https://stackoverflow.com/questions/38770934/how-to-export-to-pdf-a-confluence-page-within-a-script worked.

(Our domain is on Confluence 5.10.2 and had the  XML-RPC and SOAP APIs enabled as in solution #1)

Eugenio Rustico November 12, 2018

The "page not found" is probably a mistake in the URL. With the correct URL, curl should output the HTTP response headers, which include the Location. Maybe postman automatically parses the Location and redirects the request to it? That should be the PDF URL.

Elwyn Chow November 14, 2018

It's not that since the URL is okay with Postman then the curl command exported from Postman doesn't work.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events