Forums

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

How to Upload PDF file in a page | UpdatePage by adding a PDF file | REST API v2

Shivendra Chouksey April 22, 2025

I have found Atlassian confluence REST API v2 via their docs :- https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-labels-id-pages-get

There I found api for working with Pages (specially for my usecase)
It includes multiple API’s, I’m using get Page by Id, create page, update pages.
I was able to do the things I wanted, like creating a page, updating a page.

But now I am stuck and doesn’t find anywhere a solution to it.

In confluence page UI, we have a option to add attachment, insert file.
Similarly, I wanted to add a PDF file in my confluence page, but using REST API multipart/form.

But unable to find a way to do so, found an api but I don’t know where it was attaching a file, I couldn’t find it anywhere in my page.

https://domainName.atlassian.net/wiki/rest/api/content/{page_id}/child/attachment
(I believe this is for confluence cloud ?)
It’s response also have some links on clicking it I was landing on a json page.

I need help if anyone here worked with uploading / adding a file in confluence page using REST API please let me know how it can be done.

Please let me know of any docs if any moderator/consultant from Atlassian is reading this.

1 answer

0 votes
Jim Knepley - ReleaseTEAM
Atlassian Partner
April 22, 2025

Welcome to the community @Shivendra Chouksey 

To create an attachment, you need to use the V1 API. Parts of the V1 API are deprecated, other parts are not. This is one of the parts that hasn't been implemented in V2 yet.

ref: https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content---attachments/#api-wiki-rest-api-content-id-child-attachment-post

Shivendra Chouksey April 22, 2025

Hi @Jim Knepley - ReleaseTEAM , Thanks for sharing.
But I issue i am facing is the attachment is not reflecting under the page(pageId) against which I have send that pdf.
As per the API response it is giving some link which is taking me to a page full of json, showing my pdf name some details about when created and by me.

But it is not reflecting inside confluence page (pageId i have given).

Can you please help ?

Jim Knepley - ReleaseTEAM
Atlassian Partner
April 23, 2025

I've never seen the behavior you're describing.

If a properly structured API call to create an attachment responds as successful but doesn't result in that content appearing as part of the page, I would bring that up with Atlassian support.

Like Shivendra Chouksey likes this
Shivendra Chouksey April 23, 2025

I got some updates on this, as I said it is successfully uploading a pdf but unable to show it in a confluence page.

I found this uploaded pdf under attachments, 
{Open the confluence page against which pdf is uploaded > Clicking on three dots, present in top right corner > Attachments > Files > Showing files I have uploaded using attachment api}.


But still this behaviour is strange, I mean If a confluence page have attachments it should show explicitly, but as of current scenario it is showing a empty clean page.

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2025

Hi @Shivendra Chouksey

You don't have any problem with your REST API call to upload the attachment apparently, but Confluence doesn't automatically display attachments as part of the page, as it doesn't know how you want them to be displayed (or if you actually want them to be displayed at all, as some use cases require this). You will need to update the code of the page to display the uploaded attachment.

I would suggest to take a blank page and either apply the Attachments macro (this provides a list of all attachments), or insert a PDF into the page using the "Image, Video, or File" macro and save the page. Then take a look at the code which is generated by doing so (/api/v2/pages/{pageId}?body-format=atlas_doc_format). Then, use that code to update the page at the same time as you upload the files (in a subsequent REST call). Long story short, you need two REST calls, one to upload the file and one to update the page to show how you want it displayed.

Shivendra Chouksey May 4, 2025

Hi @Stephen Deutsch , Thanks for sharing.
I did the same, thing using two rest API, one for upload attachment and second one for updating the page with adding file macros.

Was thinking that I might be doing it wrong and there might some straight forward way to do it out properly, anyways the requirement is satisfied.

Thanks for the help.

Like Stephen Deutsch likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events