Confluence 5.5 REST API upload new version of attachment?

homeniuk August 25, 2014

Hi,

with this curl, it is possible to upload a new attachment:

curl -v -S -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=@myfile.txt" -F "comment=this is my file" "http://localhost:8080/confluence/rest/api/content/3604482/child/attachment"

but how can i upload a new version of an attachment?

i try this:

curl -v -S -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=@myfile.txt" -F "comment=this is my file" -F "version=2" "http://localhost:8080/confluence/rest/api/content/3604482/child/attachment"

but it did not work :(

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Steve Lancashire
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 27, 2014

A POST to the child resource of a piece of content attempts to create a new piece of content.

To update the existing attachment you will need to use a different resource that references the existing attachment by ID, namely : rest/api/content/{id}/child/attachment/{attachmentId}/data

See the documentation in the atlassian rest browser:

https://bunjil.jira-dev.com/wiki/plugins/servlet/restbrowser#/resource/api-content-id-child-attachment-attachmentid-data

From the documentation :

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt;minorEdit=true;comment=This is my updated File" http://myhost/rest/api/1/content/123/attachments/456/data

*Edit* Apologies, I should have checked that myself, the following works with curl 7.30

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" -F "comment=This is my updated File" -F "minorEdit=false" http://localhost:8080/confluence/rest/api/content/4751367/child/attachment/att4915201/data

The comment and minor edit flag are currently required

homeniuk August 27, 2014

Unfortunately it does not work. And your curl call isn't compatible with Confluence 5.5 REST API. I tried

curl -v -S -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=@mytext.txt" http://localhost:8080/confluence/rest/api/content/852013/child/attachment/att1081350/data

and get and statusCode 500

However, the response messages are not very helpful :(

Steve Lancashire
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 28, 2014

The following works, have ammended my answer

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" -F "comment=This is my updated File" -F "minorEdit=false" http://localhost:8080/confluence/rest/api/content/4751367/child/attachment/att4915201/data


homeniuk August 28, 2014

Very nice! "minorEdit" was missing in my curl call.

Christof Hurst September 18, 2018

Works perfect, thanks :-)

1 vote
J D
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 3, 2014

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=@myfile.txt" http://it016-d01:1990/confluence/rest/api/content/1507332/child/attachment 


Worked for me as well, to update a attachment

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 25, 2014

Try leaving off the version, Confluence should handle that itself.

homeniuk August 25, 2014

There was a reason why I've attached the version. Without it, it get {"statusCode":400,"message":"Cannot add a new attachment with same file name as an existing attachment: myfile.txt"}

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 25, 2014

Ah, I'm not sure that your "no-check" is right and I'd check the path as well - the script I've got here uses "nocheck" and /id-number/attachments" in the path rather than /id-number/child/attachment

homeniuk August 25, 2014

Maybe your script use the old REST API? Search for a solution for Confluence version 5.5 upwards.

TAGS
AUG Leaders

Atlassian Community Events