Rest API for Exporting PDF/Word Document
Asked by PASUPULA REDDY:

Hi,

could you help us with the rest api for Exporting PDF/Word Document in Confluence.

Regards,

Kulasekhar


Answers:
author: Urban_Pettersson
body: While there is no proper Rest API support for this, you can still get this to work. I have created a [GitHub gist](https://gist.github.com/castodius/84c5ec49cceca5eb9a667dec3058364e) which details the necessary steps using NodeJS.


author: Elliot Sloman
body: If you hover over the "Export to PDF" and the "Export to Word" buttons in Confluence you can see the links that are called when you press those buttons. You can do a GET on these URLs to get the objects.

So the URL would be something like (for PDF):

"confluenceurl" + "/spaces/flyingpdf/pdfpageexport.action?pageId=PAGE_ID"

The auto-generated filename is then in the "content-disposition" of the return object. But you can always set your own filename.

The content of the file is in the return object's content.

We use the above method and python to dynamically export pages to PDF when we need to.

Hope that helps!

comments: author: Ronaldo Huang
body: [@Elliot Sloman](/t5/user/viewprofilepage/user-id/2686795)

Hi,how about the URL for exporting Word?


author: Elliot Sloman
body: Seems to work as well!

The URL is simpler and something like this:

"CONFLUENCE_URL" + "exportword?pageId=PAGE_ID"

Like above, the filename is in the content-disposition header but you can always set your own if you don't want the auto-generated file name.

The content of the file is in the "content" of the return object. You can simply write that to a file.

I tested this morning with a bit of python code and it worked fine.


author: Ronaldo Huang
body: [@Elliot Sloman](/t5/user/viewprofilepage/user-id/2686795)

It doesn't work for me.My confluence server is local.

How can I export word using template?

I have tried rest api GET 'http://CONFLUENCE_URL/plugins/servlet/scroll-office/api/public/1/export-sync?templateId=com.k15t.scroll.office.default-template-1\&pageId=67415595'

But the response downloaded word is error coding.

And I also tried the rest api POST 'http://CONFLUENCE_URL/plugins/servlet/scroll-office/api/public/1/exports'

But the response is {  
"status": 403,  
"message": "User not allowed to export because of export restrictions on either space or groups."  
}

According to the document <https://help.k15t.com/scroll-pdf-exporter/latest/server/export-content-via-rest-api-125699615.html>


author: David Bakkers
body: Hello [@Elliot Sloman](/t5/user/viewprofilepage/user-id/2686795)

Using Confluence cloud, when I try doing a GET request to that URL via Postman to export the PDF, then HTML content is returned, not JSON, and there is no 'content-disposition' object.

Can you provide more details and an example for doing that GET request.


author: Larry.D.East
body: I'm working on the same type of issue but only for pdf's. If you're using Python, you can use the confluence package (<https://atlassian-python-api.readthedocs.io/confluence.html>) and the export_page function for pdf.

```
confluence.export_page(page_id)
```

As the doc indicates, if you're using Confluence Cloud, make sure when you instantiate confluence that you set the api_version to cloud.

```

confluence = Confluence( url='https://yourcompany.atlassian.net/', api_version='cloud', username=username, password=password)
```

comments: author: Dev CloudApp
body: [@Larry.D.East](/t5/user/viewprofilepage/user-id/3933778) Were you able to get the PDF exported? What is the scope that was used?

token={  
"access_token": "token_xxx",  
"token_type": "Bearer"  
}

oauth2_dict = {  
"client_id": "client_id_xxx",  
"token": token}

confluence= Confluence( url='<https://api.atlassian.com/ex/confluence/{cloud_id_xxx>}',  
oauth2=oauth2_dict)

With the above code, I am able to use the OAuth2.0 authentication and make other functions like 'get_spaces' working. However, the export_page, doesn't return the PDF. Receiving an error "Unauthorized; scope does not match"


author: Larry.D.East
body: It's been a while since I worked on this so I'll make the disclaimer upfront that it's all a little fuzzy now :) From what I can find of the source code I still have access to, I didn't specify a scope. However, a quick search turned up these two links, <https://community.developer.atlassian.com/t/unauthorized-scope-does-not-match-forge-app/49459> and <https://community.developer.atlassian.com/t/scope-does-not-match/49346>, both of which point to recreating the app as a confluence app instead of a jira app. Don't know if that's your situation, but hope it helps. Good luck!


author: Nils Bier _K15t_
body: Hi [@PASUPULA REDDY](/t5/user/viewprofilepage/user-id/3018152) ,

you might want to have a look at our [Scroll PDF Exporter](https://marketplace.atlassian.com/apps/7019/scroll-pdf-exporter-for-confluence?hosting=server&tab=overview), which lets you easily create templates using a graphical template designer, without the need to know any CSS.

Additionally you can use our [REST API](https://help.k15t.com/scroll-pdf-exporter/latest/server/export-content-via-rest-api-125699615.html) (or even [Java API](https://help.k15t.com/scroll-pdf-exporter/latest/server/export-content-using-the-java-api-172589432.html)) to perform exports automatically.

Scroll PDF Exporter is available via the Atlassian Marketplace and can be tested using a free evaluation license.

Cheers,  
Nils

comments: author: PASUPULA REDDY
body: Hi,

thanks for the reply, It would be great for us if you share the code along with the http head managers.

Regards,

Kulasekhar


author: DPKJ
body: [@PASUPULA REDDY](/t5/user/viewprofilepage/user-id/3018152) There are no rest api's to export PDF/Word out of Confluence.

But there exists SOAP API's for this - <https://developer.atlassian.com/server/confluence/remote-api-specification-for-pdf-export/>

Please do verify if SOAP is working with your version of Confluence as Atlassian team is looking to deprecate it as soon as all its features are replicated in REST.


Tags: atl-gruland

confluence-cloud

confluence-server

server