You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hi All
I am new to confluence, my task is to upload a multiple images to confluence page through rest call. can anyone give a sample example. i tried with curl but i am getting 405 error
curl -D- -u admin:password -X POST -H "X-Atlassian-Token: nocheck" -F "file=@host.txt" https://company.domain.com/rest/api/content/id/child/attachment
please any one help.
Thanks in advance
@noor basha Welcome to the community, something like this might work for you.
curl -D- -u '<USER_NAME>:<PASSWORD>' \
-X POST \
-H 'X-Atlassian-Token: nocheck' \
-F 'file=@"<FILE_PATH>"' \
'<CONFLUENCE_BASE_URL>/rest/api/content/<PAGE_ID>/child/attachment'
And the response 405 implies method you are using i.e. POST is not applicable, so please check if your page is not blocked for editing etc.
Thanks for quick response sir, I tried this it gives response 200 but image not inserting. page is blank.
curl -D- -u 'admin:password' -X POST -H 'X-Atlassian-Token: nocheck' -F 'file=@"/root/host.txt"' 'https://company.com/rest/api/content/id/child/attachment'
import requests
def upload_image():
url = 'https://company.com/rest/api/content/' + \
str(id) + '/child/attachment/'
#headers = {'Content-Type: application/json'}
#headers = {'Content-Type': 'image/jpeg'}
headers = {"X-Atlassian-Token": "nocheck"}
content_type = 'image/jpeg'
file = 'download.jpg'
files = {'file': ('download.jpg', open('download.jpg', 'rb'),content_type)}
auth = ("admin", "password")
r = requests.post(url, headers=headers, files=files, auth=auth)
print(r.status_code)
upload_image()
I tried with this script also. in both cases I am getting 200 response but page is blank. please help me. its 2nd day I am working on this same
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i tried with different approach then it is working fine. but my problem is the picture is not displaying in confluence page. picture is in attachments, i need to display in confluence page.
please give some reference to display the picture with rest api
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>}
}'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
👋 Hi there, a few of us at Atlassian would love to learn about how you use "space settings" functionality in Confluence. A facelift to the space settings is long overdue and we want to start with im...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.