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 requestsdef 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
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
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>}}'
Hi DPK J -
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 apend 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 '1628: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}}'
It looks like you're new here. Sign in or register to get started.