It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

is it possible to display image in confluence page through rest api

Hi All,

 

I am able to upload image through rest api. but i dont know how to display that image. please guide me.

 

Thanks in advance

1 answer

2 votes
DPK_J Community Leader Dec 19, 2019

@noor basha  I have already sent you a reply on your previous question.

Here is recap of that,

Displaying attachment on confluence page is another part of story and you will need to fire separate APIs for this.

You need to put something like this in your page body using API,

<ac:image>
  <ri:attachment ri:filename="atlassian_logo.gif" />
</ac:image>

Here is an working API example, in first API I'm adding image `sample.png` as attachment and later in second API call I'm displaying that in page using Confluence Structure format in body.

 

curl -D- -u '<USERNAME>:<PASSWORD>' \
-X POST \
-H 'X-Atlassian-Token: nocheck' \
-F 'file=@"./sample.png"' \
'<CONFLUENCE_BASE_URL>/rest/api/content/<PAGE_ID>/child/attachment'

curl --request PUT \
--url '<CONFLUNCE_BASE_URL>/rest/api/content/<PAGE_ID>' \
--user '<USERNAME>:<PASSWORD>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
"id":"<PAGE_ID>",
"type":"page",
"title":"Sample Page",
"space":{"key":"<SPACE_KEY_OF_PAGE>"},
"body":{
"storage":{
"value":"<p>Adding image to page</p><ac:image><ri:attachment ri:filename=\"sample.png\" /></ac:image>",
"representation":"storage"
}
},
"version":{"number":<NEXT_VERSION_NUMBER>}
}'

thanks alot sir. it worked, but curl is not working fine i tried with different approach.To display or update i used storage format then i am able to upload or modify any data in the confluence page. 

thanks alot for you help and replay

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

How is your team having fun and bonding, remotely, utilizing Confluence?

Thanks everyone for answering last week’s question. The winner of the random drawing from those who commented is: @LarryBrock I’ll contact you separately with your prize details. This wee...

327 views 9 7
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you