Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

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

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

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

Ignored forever ...

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

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

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

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.

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you