Dear all,
I'm trying to add 'watcher' support from our iPhone app that access JIRA using REST API.
I try to invoke "/rest/api/2/issue/<key>/watchers" and always get "400 bad request" error message! I use http method "POST" with data containing user name requesting to watch. In JIRA REST API doc, it say:
acceptable request representations:
<h6>Example</h6>
"fred"
I try to send only "fred" string, json array "fred", dictionary "name=fred", but NOTHING works!
DELETE request works perfectly.
Please help as we want to release update for our iPhone app ("Resolveit for JIRA") as soon as possible.
Best regards,
Joe
Community moderators have prevented the ability to post new answers.
Try sending the data with double quotes. Not just "fred" string but "\"fred\"". The following curl worked for me:
curl -i -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '"jobinkk"' http://localhost:8080/rest/api/2/issue/TEST-1/watchers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
curl -D- -u admin:admin -X POST --data @C:\Users\folder\Desktop\testRest.json -H "Content-Type: application/json" http://jirainstanceon8w7:2990/rest/api/2/issue
what is wrong with my command ? Am i missing some parameter in it to create an issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi I am using postman to test this REST command I have tried with quotes, without quotes, with keys but nothing seems to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hope this helps someone as it was painful to determine what works
curl -i -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d """jobinkk""" http://localhost:8080/rest/api/2/issue/TEST-1/watchers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does anyone know if it's possible to add a list of names to the watchers list in a single call, or would it have to be a separate call for each user to be added? (I tried a couple of different ways of passing in a list of names to the API, but it only ever took the first name).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried to add a watcher to one JIRA issue, but anyway, it returns "bad request".
I can update assignee, comment, labels, .... with the similar code below, only watcher got me.
Thanks in advance.
my code is as below:
public void updateJiraWatcher(string key,string watcherName)
var request = new RestRequest()
{
Method=Method.Post,
Resource = "/rest/api/2/issue/"+key+"/watchers",
RequestFormat= DatFormat.JSon
};
string jsonWatcher ="{\""+watcherName+"\"}"; // "{\"username\":\""+watcherName +"\"}; ** doesn't work too
request.AddParameter("application/json",jsonWatcher,ParameterType.RequestBody);
var response = GetRequestsResponse(request);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
I have the same problem, always got a bad request ,statuscode :400,
the above answers don't help,
my code below:
I tried to add a watcher to one JIRA issue, but anyway, it returns "bad request".
I can update assignee, comment, labels, .... with the similar code below, only watcher got me.
Thanks in advance.
my code is as below:
public void updateJiraWatcher(string key,string watcherName)
var request = new RestRequest()
{
Method=Method.Post,
Resource = "/rest/api/2/issue/"+key+"/watchers",
RequestFormat= DatFormat.JSon
};
string jsonWatcher ="{\""+watcherName+"\"}"; // "{\"username\":\""+watcherName +"\"}; ** doesn't work too
request.AddParameter("application/json",jsonWatcher,ParameterType.RequestBody);
var response = GetRequestsResponse(request);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found that the parameter variable needed the quotes. Code solution below:
....
public void add_jira_Watcher(String issue_ID, String watcher) {
try {
.....
ClientResponse response = webResource.header("Authorization", "Basic " + auth_base_64).type("application/json").accept("application/json").post(ClientResponse.class, "\""+watcher+"\"");
.......
}
.....
Hope this helps anyone.
TRX
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I am also getting a 400 error. I'm doing this with java and am curiuos if anyone got the json syntax to work with the JRest APIs via Jersey classes?
ex)
//**************************************************************
// Add watcher to an existing JIRA issue
//**************************************************************
public void add_jira_Watcher(String issue_ID, String watcher) {
try {
String ji_rest_edit_URL = "http://"+ji_Host+"/rest/api/2/issue/"+issue_ID+"/watchers";
final String json_add_Watcher = "{\"username\": \"+watcher+\"}";
System.out.println("URL: " + ji_rest_edit_URL);
WebResource webResource = client.resource(ji_rest_edit_URL);
ClientResponse response = webResource.header("Authorization", "Basic " + auth_base_64).type("application/json").accept("application/json").post(ClientResponse.class, json_add_Watcher);
@SuppressWarnings("deprecation")
int statusCode = response.getResponseStatus().getStatusCode();
if (statusCode != 204) {
jrest_API_Logger.info("add_jira_Watcher() --> Watcher added failed to issue "+issue_ID+": "+statusCode);
} else {
System.out.println("wachter: " + watcher + " was added to jira issue: "+issue_ID+": "+statusCode);
}
} catch (ClientHandlerException ex) {
jrest_API_Logger.info("add_jira_Watcher() ClientHandlerException ex.getMessage(): " + ex.getMessage() + ": " + issue_ID);
} catch (Exception ex) {
jrest_API_Logger.info("add_jira_Watcher() Exception ex.getMessage(): " + ex.getMessage() + ": " + issue_ID);
}
}
Thanks in advance.
TRX
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just my $0.02 here for someone who is using .NET to post. Make sure you enclose your string between quotes:
string.Format("\"{0}\"",userName)
Otherwise it was failing in my env since we are using firstname.lastname for the usernames and that period in the middle was the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this still valid? I'm getting the 400/Bad Request error using
a _curlrc file with
-H "Content-Type: application/json"
-k
-u username:password
--silent
--show-error
and a command line of
./curl -i -H "Accept: application/json" -X POST -d '"username"' https://hostname.jira.com/rest/api/latest/issue/ISSUE-id/watchers
"The request sent by the client was syntactically incorrect (Bad Request)"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.