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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,508,236
Community Members
 
Community Events
181
Community Groups

400 Bad Request when updating an issue via REST API

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

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."}}

 

 

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

Like Chris Payne likes this

jrickards you are awesome

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"?

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.

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

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

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

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.

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"?

Ignored forever ...

Suggest an answer

Log in or Sign up to answer