Problem adding a label to an attachment using the Confluence UI REST API

I'm trying to use the Confluence UI REST API and do a POST request to add a label to an attachment. I tried using curl to do this, but I keep getting an error in HTML, with title "Oops - an error has occurred - Confluence." My command looks like this:

curl -u $username:$password -X POST -H "Content-Type:application/json" -d @data.json ${hostname}/rest/uri/1.0/attachment/${attachmentID}/labels

The data.json file contains:

{"name": "test", "id": 8787878}

I am able to use the the GET and DELETE methods in the Confluence UI REST API with cURL. I'm not sure if the data from the JSON file is in the correct format or even the correct data and I am providing an arbitrary id.

1 answer


Try to change the data part, the way you send the data,

curl -u $username:$password -X POST -H "Content-Type:application/json" -d @data.json ${hostname}/rest/uri/1.0/attachment/${attachmentID}/labels

The following curl will help you to post the data to server, try it.

curl -D- -u admin:admin -X POST --data {\"body\":\"hello\"} -H "Content-Type: application/json" http://localhost:2990/jira/rest/api/2/issue/TEST-1/comment</code<>>

I dont know whether it is correct, But do let me know.

Hope this helps!

Thanks. I tried with the new format of data, but it doesn't seem to work for this particular situation in Confluence. Your answer probably works for adding comments to JIRA issues, and I'm assuming that the data format will be different since I'm trying to pass label information to an attachment.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,927 views 27 12
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you