Confluence - Images not rendered through content REST API.
Asked by Tanushree Mahajan:

This is my curl call:  
curl ~~D~~ -X GET -H 'Authorization: Basic \*\*\*\*\*\*\*\*\*' -H 'Content-Type: application/json' '<https://mydomain.atlassian.net/wiki/rest/api/content/$pageId?expand=metadata.properties.myprop,bb,body.view,version,container>'

I get all the text and html in response. But images are not displayed. When the session is going on to Confluence, images are displayed, otherwise not!

Please help!


Answers:
author: Rajpv
body: Hello Stephen, [Stephen Sifers](https://community.atlassian.com/t5/user/viewprofilepage/user-id/2145523)

I see the below curl cmd working as expected...

when i post below request - i could the image rendered on the confluence page.

But when i try to render another image - it is overwriting the existing/first image on the confluence page.

My question is how do we append the images in the confluence page instead of overwriting... Please suggest. thanks

curl --insecure -k --request PUT \\  
--url '<https://confluence.global.standardchartered.com/rest/api/content/2377271484>' \\  
--user '1628738:\<pwd\>' \\  
--header 'Content-Type: application/json' \\  
--header 'Accept: application/json' \\  
--data '{  
"id":"2377271484",  
"type":"page",  
"title":"NewPTPage",  
"space":{"key":"CC"},  
"body":{  
"storage":{  
"value":"\<p\>Adding image to page\</p\>\<ac:image\>\<ri:attachment ri:filename=\\"values.png\\" /\>\</ac:image\>",  
"representation":"storage"  
}  
},  
"version":{"number":14}  
}'


author: Stephen Sifers
body: Hello Tanushree and welcome to the Community!

The info you provided paints a clear picture of what you're wanting and are accessing. The first thing I see which might explain why your images are not showing is that you're not viewing the storage format of the Confluence page.

To explain a bit more detail into this, I'll explain how images are displayed within Confluence. When you have a page within Confluence, you have 2 options to display an image within a page. The two options are a linked image (which exists somewhere else and is referenced as an image) and attached images (which are attached to a page within Confluence and displayed within a Confluence page). Both of these are viewed differently when viewing the Confluence page via the REST API. You are going back to why you're not able to see the image within your REST API call. From your API call, the endpoint you're accessing is correct.

Let's go back to why you're not able to see the image within your REST API call. From your API call, the endpoint you're accessing is correct. However, if you want to see an image which is attached to a Confluence page, you will need to view the child/attachment to gain access to the images. The endpoint to access attachments is [GET /rest/api/content/{id}/child/attachment](https://docs.atlassian.com/ConfluenceServer/rest/6.14.1/#api/content/%7Bid%7D/child/attachment-getAttachments). With this endpoint, you would make a call to request any attachments for the parent page which may have an image attached.

I hope this explains why images are not directly displayed via the endpoint you're requesting along with how images may be stored and displayed within Confluence.

Regards,  
Stephen Sifers

comments: author: Tanushree Mahajan
body: I have used this API already. It gives a json response with a *_links* attribute which has *download* and *webui* attributes in it.

I merged the atlassian *base url* and the *download* link from response and hit the merged link in browser, it took me to the login page of atlassian.

Which link am I supposed to provide to the image source to display the image or make it downloadable?

Also how we should add images to confluence page? Right now we are just copy pasting the image in the editor. We can change the way so as to get the response in REST API.


author: Stephen Sifers
body: Hello Tanushree,

Thank you for replying and providing additional clarification.

If you want to access page attachments externally then, you will have to authenticate to get to the files attached. You would either need to pass through authentication when attempting access or enable anonymous access to the site.

For setting up Confluence anonymous access, please review [Setting Up Public Access](https://confluence.atlassian.com/doc/setting-up-public-access-156.html). This would allow you to make content available without having to authenticate to Confluence. However, this does not apply to all applications as this would let all content to be publically available.

I hope this helps clarify how to access your attachments within Confluence.

Regards,  
Stephen Sifers


author: dinesh korgaokar
body: hello [@Stephen Sifers](/t5/user/viewprofilepage/user-id/2145523) can u show example for to authenticate to get to the files attached.

i am been trying to authenticate image from page not able to do it. using token to authenticate.


author: Nalin Agrawal
body: What I dont understand is why attachements need Anonymous access? What is the security concern? Some user can very well expose sensitive data in text as well, which is freely avaialble via APIs, but for some wierd reason attachments are not.


author: Jamie Colclough
body: I agree with [@Nalin Agrawal](/t5/user/viewprofilepage/user-id/4472164), I am trying to use the confluence api to return a page that I can then render in my NextJS application. It all works perfectly apart from I can't display the images in my application, even though I have clearly managed to be authenticated to get the url from the api in the first place.

I have enabled anonymous access for my space and pages but the images still won't display. If I try and click on the image link in inspector, it redirects me to the Atlassian login page which is not what I was hoping for!

[@Stephen Sifers](/t5/user/viewprofilepage/user-id/2145523) How can I get this to work?

And has anyone else managed to get this working?


Tags: atl-adm

rest-api