Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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:
Any help will be much appreciated!
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
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.
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"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"?
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.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.