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

Using /rest/api/2/group/user POST method to add group to a user results in Unexpected character error message

Goran Starcevic August 11, 2014

This is an experimental API call I'm trying to use: https://docs.atlassian.com/jira/REST/ondemand/#d2e651(currently v6.3)

When I issue a following command:

curl -D- -u goran:HIDDEN -X POST -d 'username=testuser&groupname=testgroup' -H "Content-Type: application/json" https://SUBDOMAIN.atlassian.net/rest/api/2/group/user

I get a following response:

{"errorMessages":["Unexpected character ('u' (code 117)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@13adc1b; line: 1, column: 2]"]}

The same API call works fine with a DELETE METHOD, i.e.:

curl -D- -u goran:HIDDEN -X DELETE -G -d 'username=testuser&groupname=testgroup' -H "Content-Type: application/json" https://SUBDOMAIN.atlassian.net/rest/api/2/group/user

works as expected and removes user from the group specified.

2 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
Andreas Ebert
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.
August 11, 2014

According to the REST api you linked, the POST-method of the /group/user resource does only expects 1 URL parameter: groupname. In contrast, the DELETE-method also expects a 2nd URL parameter: username.

I looked at the source of that REST resource and figured out how to add the user name:
It expects a user-bean in the form of a JSON-object in the POST body. The JSOn object consists of a field "name" which contains the user name.

So in terms of jQuery try something like this:

AJS.$.ajax({
  type: "POST",
  url: "/rest/api/latest/group/user?groupname=testgroup",
  contentType: "application/json",
  data: '{"name": "testuser"}'
});

This Stack Overflow thread helped writing the jQuery POST request.

Goran Starcevic August 12, 2014

Many thanks - it worked like that.

Nabil Sayegh September 25, 2014

Thank you. Passing a string as data works. The atlassian documentation seems to be wrong: https://developer.atlassian.com/display/GADGETS/Making+Ajax+Calls

0 votes
Goran Starcevic August 11, 2014

The same response occurs when I try the same request via jQuery:

jQuery.ajax({
  type: "POST",
  url: "https://SUBDOMAIN.atlassian.net/rest/api/latest/group/user",
  contentType: "application/json",
  data: {username: "testuser", groupname: "testgroup"}
});

TAGS
AUG Leaders

Atlassian Community Events