It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Add Label with REST API

Not sure what's going wrong, but when I try to add a label with the REST API, I end up getting a XSRF check failed error.

Maybe I'm not clear on what needs to be passed for adding a label to a page. Based on the API documentation, I figured something like this would work:

https://my_confluence.com/rest/api/content/123456789/label?prefix=global&name=test2

2 answers

1 accepted

0 votes
Answer accepted

I'm not on their cloud. We host it ourselves.

You still need the header. XSRF check is there in server as well.

But why does it only impact the label? I've been able to make all sorts of other calls without this issue.

I am not sure about that!

Well, I added it and tested with the URL above, but it gives me a 400 error with the message "Could not parse Labels from ". Is the above how you set up labels for a post?

Check out: https://docs.atlassian.com/confluence/REST/latest/#content/{id}/label-addLabels

Sample input:

[
    {
        "prefix": "global",
        "name": "label1"
    },
    {
        "prefix": "global",
        "name": "label2"
    }
]

I've seen that, as stated above, but it's not working. Even after adding the header, as you suggested, I receive the 400 error as per my previous comment.

Well, the header seeoms to have helped with the XSRF error. Now you are getting a bad input error. From what I see, you are not sending a json array. Can you try sending it with the proper fomat?And with the content type header et al?

You will find some examples here: https://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples

Yep, seen those examples. Done all of them with Postman. All of them worked (even without the header for the XSRF error, which only happened when trying to post a label (I could post pages without any error)). 

Putting in the header and my authentication in Postman, then using this format (as above): https://my_confluence.com/rest/api/content/123456789/label?prefix=global&name=test2 results in an error that it "Could not parse Labels from ".

I've managed to create pages, move pages, copy pages, delete pages, modify pages, but I can't add a label.

https://my_confluence.com/rest/api/content/123456789/label?prefix=global&name=test2 is not valid from what I see. I am not in a position to test it now but the API is expecting a json array as far as I see from the doc. Similar to the create new page example.

Fair enough; that's what I was wondering.

Hmm...now I'm getting a "No content with id" error. The ID matches the page ID.

Did you manage to get this working? I have a similar problem with the code below. 

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

Server returns "Could not parse Labels from"

@per.lofgren

try changing the -d "[{"prefix": "global","name": "label"}]" to 

-d  '{"prefix": "global","name": "label"}'

Yeah, I did get this working. I had to use: {"prefix":"global","name":"LABEL"}

does it change the case lik "label" instead of "LABEL" 

I am getting lowercase label 

Labels are converted to lower-case. In the example I provided, I just put label in caps since it should be replaced with your label. I should have put it as <your_label_here> or something like that.

is there a way to keep labels as they are, i.e.  not changing case ?

No, there is not. Testing in Confluence 6.4.2, putting in a label on the page with capital letters or a mix, the label is changed to all lower-case.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted 3 hours ago in Industry Groups

Upcoming Team Tour Government Symposium in Washington D.C.

Calling all Community members from the Washington D.C. area! Atlassian’s Team Tour is heading to your city to host a Government Symposium on May 1st. Join our team and other government agencies to le...

10 views 0 1
View post

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