In the rest API Documentation (https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-edit-issues-6291632/)
I found something like this command:
curl -D- -u fred:fred -X PUT --data "json_data" -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31
I have very little idea from curl and http requests, so I used a converter on https://curl.olsh.me (see picture below)
I of course replaced the link, fred:fred with my username and password+token and replaced "json_string" with actuall fields.It still does not work. I get response 200:OK but the ticket doesn't change.Also why does the converter tell me that parameter -D- is not supported? Is it because of this, that it doesn't work?What am I missing?
Hi @CremeFresh ,
would you please share your request body (provided json_string) with us? In general I can't see anything wrong with your request...
The PUT request sort of worked, hence the 200 response, but you didn't tell JIRA what to update because you didn't supply the array of fields to update. Your request essentially says 'Update ticket QA-31' and nothing else.
If the PUT request is properly formed and executed, you should receive a response with a status of "204 No Content".
With regards to that tool reporting that '-D-' is not supported, I think there's a typo on that Jira documentation page, as curl command options start with a single hyphen for the abbreviation or double hyphens for the long version; there is no following hyphen, unless that is an obscure flavour of curl.
'-D' is the abbreviation for '--dump-header' option, so the curl command would be:
curl <strong>-D</strong> -u fred:fred -X PUT --data {see below} -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31
I tried that with the tool, but it still didn't accept it, so I think it's just a limitation of the tool. Dumping the header is of no great benefit, so you can omit that option just fine and the tool will process and translate it to C# without the error message.
So, as an example, the following curl command to assign an issue to the user Harry (the first example on the Jira documentation page), using fully expanded options, would be:
curl --user fred:fred --request PUT --data '{"fields": {"assignee":{"name":"harry"}}}' --header 'Content-Type: application/json' --header 'Accept: application/json' --url http://kelpie9:8081/rest/api/2/issue/QA-31
Hello, thank you both for taking time by replying @Hana Kučerová and @[deleted].
To be more concrete now, this is how it looks like:This is my actual code:
And my json-string which is in data looks like this:
I am 100% sure that these version names and values exist, because I can create the tickets with these values. But changing the fields doesn't work. It keeps on staying the old values/names for the fields above.
I can provide you the exact response when I am at work.
What other testing have you done to isolate the cause of the problem?
1. Have you confirmed that the C# code is correct? IE, can you use that code to update just the value of customfield_14702, or to set some other Jira setting like the assignee?
2. Have you confirmed the JSON data of the request is valid? IE, can you can use that same JSON data in a REST API test tool like Postman to set the field values?
3. Have you tried putting the JSON data directly into the code not a variable? IE, does the request work if don't have it stored as a variable, but as a string typed directly in the code?
In your variable 'data' you have started with an outer array called '[JSON]' ... what is the purpose of that?
It's not clear whether you're asking for someone to help you debug possibly faulty C# code, a faulty REST API request, or a faulty request construction method.
@[deleted]
1. I cannot update a single field. Also tried it with other fields and simpler data strings.
2. Yes, I use this form of json also when creating tickets and it works
3. No, because of 2., but I will still try
The variable data doesn't have another array [JSON]. In Debug-Mode I can chose how to view the data e.g. as string, as HTML or as JSON. The string form starts with something like {\fields\: etc...
I am sorry if its not clear what I am asking for, because I really don't know. I wish I just could tell you that its faulty c# code, but everything seems to work fine, because I also get the 200 response. One weird think I had though: Even though I used totally jibberish username:password, I still got the 200 response: OK and also no crashes. How can that be?
Hmm. If your C# code above works to create a ticket using a POST request, then it should work for doing a PUT request. As to why you get no error with an invalid username / password... that is very strange.
Sorry, but my C# isn't good enough to spot any specific faults in the code. You might have to Google some other C# examples, as all the examples on the Jira Cloud REST API reference page are for other languages.
Personally, I use Postman to pre-test any tricky requests to the REST API to make sure my JSON data and the request is properly formed, as it is very interactive with error logging and reporting, plus it allows you to abstract your request from the code you're using to submit it.
Sorry I can't help much further.
Thank you anyways,
I will try using Postman.
I just used Postman to try updating some fields in an existing issue by doing a PUT request to the same Jira Cloud REST API v2 endpoint you've tried and it worked fine, and I got the expected '204 No Content' response:
When I tried the same request with no JSON in the body of the request, I got the expected '400 Bad Request' response. When I tried the same request with faulty credentials, I got the expected '401 Unauthorized' response.
So, I've just noticed in your screenshot of your C# code, you've blanked out the part of the connection URL string for your Jira instance.... including if you've specified a port. You're not trying to make the connection on port 8081 are you? That's only a example shown on the Atlassian page for a possible custom configuration.
By default, the REST API works on port 443. the same as the web interface. If you haven't changed the default port, you should omit any port number in the URL connection string.
That could be it. My link looks like this:https://cocoa.myfirmaname.de/sjira/rest/api/2/issue/{projectName}-{ticketID}
myfirmname is in this case of course a placeholder for the real name
When I try the link above with the correct projectname and ticketID , I open up the website as json format. So thats why I considered it to be the right link.
.
I just tested it with Postman and there I cannot even do a Get Request.I think my authentification is somehow incorrect?I choose Basic Auth.Our systems works like this: -Username-Password+TokenI figured that this type of Auth is Basic
I finally solved it by going a different route:Just like when I create tickets, I used a WebDriver to login. Then I got the cookies and used that for a HttpRequest. I then stream the data to the server. I did the same just with the PUT method so to speak.
Glad to hear you found a method that works, but there are some other bizzare things about your authentication method that aren't explained.
1. If you are using Jira Server, not Jira Cloud, the REST API only recently acquired user tokens instead of passwords for authentication (read this article). When using the new tokens, you use them only, not password+token, so that means you're not using that version of Jira Server and the native user tokens feature.
2. This leads me to think you have some sort of third party tool like API Tokens for Jira, or something similar that generates web session cookies. You may want to check with your Jira admins and confirm exactly what authentication methods are enabled. If Basic Auth has been turned off, then consider re-coding your C# to use OAuth wholly; if not and you have the latest version of Jira, use Basic Auth with the native username / token instead.
Good luck
It looks like you're new here. Sign in or register to get started.