Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Confluence Rest API Add label

per.lofgren February 19, 2017

Hi,

I have got a problem that I hope someone here could help me with. I am trying to add a label to a page using curl. Below is the code I use. 

curl -u user:pass -X POST -H "Content-Type: application/json" -d "[{"prefix": "global","name": "label"}]" "https://my.confluenceserver.com/rest/api/content/2384495/label"

The authentication piece is working but it seems like the parameters I am using is invalid. The return error i am getting is. 

{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[]},"message":"Could not parse Labels from [{prefix: global,name: label}]"}

I have been playing with the REST API browser as well but I get the same error there. I can successfully delete or list labels but the POST does not seem to work. 

Any ideas? 

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Per Löfgren (Qlik) February 22, 2017

Managed to get this working. Had to use double double quotes  

curl -u user:pass -X POST -H "Content-Type: application/json" -d "[{""prefix"": ""global"",""name"": ""hello""}]" "https://my.confluenceserver.com/rest/api/content/1234567/label"

Francis Woon September 20, 2017

Finally got this to work...in a nutshell ....and no NOOO double-quotes needed

Methods

1)

curl -u username:password -X POST -H "Content-Type: application/json" -d '[{"prefix": "global", "name": "abc"}]' "https://myconfluence/rest/api/content/9999999999/label"

 

The -d <data> needs to be a json compliant syntax format

You can just import json and get the exact string:

>>> import json
>>> data = [{'prefix':'global','name':'abc'}]
>>> json.dumps(data)
'[{"prefix": "global", "name": "abc"}]'

2)

You can also use the request to do this if you are using python

3)

Or you can follow the example to update a page adding in the "metadata":{"labels":[{"prefix": "global","name": "label1"}]}

Like Landon Thomas likes this
TAGS
AUG Leaders

Atlassian Community Events