I am trying to set up a script I have to send a specific type of file to a Confluence page I have set up. I have tried to use the REST API information that is provided, but I am not sure if I am setting it up correctly. For now I am just trying to use a curl command since the script I have is written in BASH.
The specific page url looks like (nearly identical to) this: https://<my-company>home.atlassian.net/wiki/spaces/TA/pages/<9-digit-number-here>/Recent+Test+Results
My thought would be that I would need to use the "Upload an attachment" endpoint as seen here, but I am not sure if I am configuring it correctly. Thoughts? I have tried plugging in values for the different pieces of the endpoint url, but not sure if they are correct. Thanks in advancehttps://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples
Hi,
Could you please provide some details:
1) What Confluence do you use: cloud or server? And version. Because you link looks like Cloud, but link to Confluence docs you provided is for Server version.
2) What does it mean - "not working"? Could you provide full curl command and error text?
3) What type and size of file are you trying to upload? Does it fit into system allowed Attachment maximum size? By default it is 100MB, but maybe you changed it.
Hi Anton,
Thank you for replying. To answer your questions:
1.) I wasn't sure at first if I was using Cloud or Server (had never really used this service before so couldn't really tell), but I've discovered that it is the Cloud. I've since gone into that documentation and seen what I can use.... however, still unsure of how to proceed.I am hoping to upload an attachment to a specific page that I created. Upon looking through the documentation I believe that I should be trying this curl (from https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-child-attachment-post):
curl -D- \ -u admin:admin \ -X POST \ -H "X-Atlassian-Token: nocheck" \ -F "file=@example.txt" \ -F "minorEdit=true" \ -F "comment=Example attachment comment" \ http://myhost/rest/api/content/123/child/attachment
I tried uploading a simple txt file as an attachment, but still not sure if I am adding the correct values for the specific page. I assume that the url should look something like this:
curl -D- \
-u <my-user-email>:<my-password> \
-X POST \
-H "X-Atlassian-Token: nocheck" \
-F "file=@<name of file to send>" \
-F "minorEdit=true" \
-F "comment=Trying this out" \
http://augusthome.atlassian.net/rest/api/content/<9-digit-number-which-I-assume-is-the-space-id>/child/attachment
When I submitted this in my terminal I got an error of:
(26) couldn't open file "firmware.txt"
I will continue to play around with this, but I'm a little confused about why the "@" needs to be before the filename, and if I am actually pointing to the correct place.
The files that I am trying to upload ultimately are just simple PNG files, about 6911 bytes.
To give you an example of what I had been getting prior to this most recent attempt, here is the curl command and the response I was getting before:
Curl command:
curl -v -S -u <username>:<password> POST -H "X-Atlassian-Token: no-check" -F "file=Lock_Firmware/CHART/EUROPA/EUROPA-1.7.8-2017-11-01-12-37-16.png" -F "comment=11/09/2017 EUROPA 1.7.7" "http://<myhost>/rest/api/content/211845263/child/attachment"
Response:
* Rebuilt URL to: POST/
* Could not resolve host: POST
* Closing connection 0
curl: (6) Could not resolve host: POST
* Trying <my-host-ip>...
* TCP_NODELAY set
* Connected to <myhost>(<myhost-ip>) port 80 (#1)
* Server auth using Basic with user '<my-username>'
> POST /rest/api/content/211845263/child/attachment HTTP/1.1
> Host: <myhost>
> Authorization: Basic <some-hash>
> User-Agent: curl/7.54.0
> Accept: */*
> X-Atlassian-Token: no-check
> Content-Length: 321
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------2bda88f822a47675
>
* Done waiting for 100-continue
< HTTP/1.1 301 Moved Permanently
< Content-Type: text/html
< Date: Tue, 14 Nov 2017 21:32:06 GMT
< Location: https://<myhost>/rest/api/content/211845263/child/attachment
< Connection: Keep-Alive
< Content-Length: 0
* HTTP error before end of send, stop sending
<
* Closing connection 1
1) About @ in curl:
<span>--data-binary <data> (HTTP) This posts data exactly as specified with no extra processing whatsoever. If you start the data with the letter @, the rest should be a filename. Data is posted in a similar manner as --data-ascii does, except that newlines are preserved and conversions are never done. If this option is used several times, the ones following the first will append data as described in -d, --data.</span>
2) (26) couldn't open file "firmware.txt" - try to use absolute file to path
3) It seems to me there's an error. URL should be in -X option as far as i know.
curl -D- \ -u admin:admin \ -X POST http://myhost/rest/api/content/123/child/attachment \ -H "X-Atlassian-Token: nocheck" \ -F "file=@example.txt" \ -F "minorEdit=true" \ -F "comment=Example attachment comment"
It looks like you're new here. Sign in or register to get started.