400 Bad Request when updating an issue via REST API

Mark Everest December 26, 2013

Hi,

I have successfully managed to search for issues, create and edit versions in Jira via the REST API but I am really struggling to update any issues.

Whenever I try to use a PUT to update individual fields I get the horrible 400 Bad Request error and no extra details to tell me why the request is bad - this error is just as good as saying "something hasn't worked".

My C# code is as follows (please note that I have just put everything into one bit of code here to show the workings - the creation of web request and response is working perfectly for versions):

var request = WebRequest.Create("http://jira-devt:8080/rest/api/2/issue/51850");
request.Method = "PUT";
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("admin:password")));
request.ContentType = "application/json";
var json = string.Format("{{ \"update\": {{\"summary\": [{{\"set\": \"plop\"}}] }} }};");
request.GetRequestStream().Write(Encoding.ASCII.GetBytes(json), 0, json.Length);
var response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var output = reader.ReadToEnd();

Looking at other posts I should be able to see what issue fields I can update by putting the following in my browser:http://jira-devt:8080/rest/api/2/issue/SUN-2743/editmeta

... and when I do I get the following response:

{"fields":{}}

So my questions:

  1. How can I diagnose the 400 error a bit further to find out what is going on?
  2. Why is my update not working? I have tried various methods detailed in the API documentation.
  3. Should 'editmeta' show more stuff? I can edit successfully in the UI.

Any help will be much appreciated!

8 answers

3 votes
James Rickards (Personal) December 15, 2015

If your using powershell, the following snipit should help.

Try {
  $response = Invoke-WebRequest -URI $requestURI -Headers @{"Authorization"=$JiraAuthToken} -ContentType application/json -Method Post -Body $RequestBodyJson -Verbose
} Catch [System.Net.WebException] { $exception = $_.Exception
  $respstream = $exception.Response.GetResponseStream()
  $sr = new-object System.IO.StreamReader $respstream
  $ErrorResult = $sr.ReadToEnd()
  write-host $ErrorResult 
}

The trick is to load the response from the exception and read the response stream. Your output will look something like the following...

{"errorMessages":[],"errors":{"issuetype":"The issue type selected is invalid."}}

 

 

Hans Riethmann September 17, 2020

a few years later and it still saved my time, thanks mate 

Like Chris Payne likes this
Chris Payne May 11, 2021

jrickards you are awesome

3 votes
Mark Everest December 29, 2013

OK no answers here and that is forgiven since it is Christmas! However, I battled on and managed to work out the solution!

The user I was using (admin) doesn't have edit access to the issues I am trying to update.

So, this has solved question 2 above, but please how can I find the more detailed error information from Jira that should have told me "access is denied"?

0 votes
G. Ann Campbell November 6, 2014

I get the same response when I try to update summary, but it works just fine with a custom field.

 

There must be intricacies (or permissions) they haven't explained that are required to update... "core" fields.

0 votes
Eric Sylvestre July 16, 2014

You can use a tool like Fiddler to trace your request to the API. You would be able to the much more details in the response than the error code 400 returned in you .NET app.

0 votes
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 23, 2014

What does JIRA say now to you? I'm seeing proper error messages in REST response if my user doesn't have permission:

{"errorMessages":[],"errors":{"project":"You do not have permission to create issues in this project."}}
{"errorMessages":["You do not have permission to edit issues in this project."],"errors":{}}

Is that what you expect?

In case when there is login problem due to captcha you'll get that information in header (with 403 resonse):

X-Authentication-Denied-Reason: CAPTCHA_CHALLENGE; login-url=http://localhost:8090/jira/login.jsp

Mark Everest April 10, 2014

Hi,

I don't actually get a REST response.

I create my request, send it for a response and .NET throws a System.Net.WebException that simply states "The remote server returned an error: (400) Bad Request."

Has anyone used REST to Jira from .NET before? Is there something I am doing wrong?

Thanks

0 votes
Roald Bankras March 23, 2014

Two things come to mind, but as you have updated versions successfully, i don't think it's gonna help you.

1. Does your jira allow for basic authentication?

2. I received the 400 when I didn't send the data as a string, but as a js object. I don't know much about c#, so I don't know how you're sending the data.

0 votes
Mark Everest March 23, 2014

Indeed - can anyone assist with this part of the question:

How can I find the more detailed error information from Jira that should have told me "access is denied"?

0 votes
Vanishree kumari March 17, 2014

Ignored forever ...

Suggest an answer

Log in or Sign up to answer