I'm using the following C# code to POST a version to Jira, but it returns a 403. I have other code to PUT an edit to a version with no problem, but POST errors, so I think my code is correct overall since that is working. At one point this was working perfectly, but we upgraded our jira version this year and it stopped working afterwards.
var req = (HttpWebRequest)WebRequest.Create(url); req.Headers.Add("Authorization: Basic " + Base64Encode(Creds.GetCredString())); req.UserAgent = UserAgentString; req.Method = method; req.ContentType = "application/json"; req.ContentLength = data.Length; req.Accept = "application/json"; req.Headers.Add("X-Atlassian-Token", "nocheck"); var pdata = Encoding.ASCII.GetBytes(data); using (var stream = req.GetRequestStream()) { stream.Write(pdata, 0, data.Length); } _log.Debug($"{method}ing to {url}: {data}"); var res = req.GetResponse(); using (var strm = res.GetResponseStream()) { StreamReader reader = new StreamReader(strm); return reader.ReadToEnd(); }
to url
http://ourdomain:8080/rest/api/2/version
My data is like
var json = $@"{{ ""name"": ""{name}"", ""startDate"":""{date:yyyy-MM-dd}"", ""project"":""{Settings.Project}"", }}";
The user credentials (my login) have no problem with this on the UI. I tried to inspect the UI POST to see if i was doing anything wrong, but it matched as much as it could. This is a utility program to help us automate our version releases.
What am I doing wrong? Is there some setting for this for the uesr for API only?
Apparently there is some problem using c#'s WebRequest.Create() so i changed it to use HttpClient.PostAsync() and it worked. Very odd that this stopped working, maybe I changed it at some point and forgot for some reason.
This issue is now resolved, thanks for your help!
The 403 error is an indication that the user account credentials does not have permissions to create/edit the version. Does this version already exist in the project? Or are you using this script to create a new one?
What version of Jira are you using now?
What version did you upgrade from?
I don't see a problem with your request itself, those fields should be sufficient to create/edit a version provided that your user credentials has rights to do so in that specific project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm trying to POST a new version, so yes i'm using this script to create a new one.
We are on jira 7.X, not sure exactly which version we upgraded to / from.
I tried doing a GET to /mypermissions to see what permissions i have but couldn't find anything relevant to this action. Is there a specific permission i need that I can show that I do or don't have?
My user has permission to do this in the UI as I said in original question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to the REST docs on this endpoint https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/version-createVersion
a status 403 error code means:
Returned if the currently authenticated user does not have permission to edit the version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> Interested to learn more
What information I can give you that would help debug this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I could learn more about what version of jira this had been working on, and what version you're using now, it would help me to better understand if this was a change to the API we made between major/minor version changes to Jira.
I'm also looking for other ways for myself to recreate this problem so I can better understand it. So far I haven't been able to recreate this. So I'm wondering if it might be more C# specific, as I'm not well versed in that specific language. Are you building a plugin for Jira when using this code? Or is this some kind of script/custom application here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Currently on 7.13.1, we upgraded again recently.
Originally we were on 6.x, I'm not sure the exact version, which was working fine. Then we upgraded to 7.8 when this problem first occurred. That was nearly a year ago, I didn't really try to solve the problem until Dec this year when I opened this ticket.
I tried to create a CURL command to do this and the POST was successful, so it must be something with the way my C# code is creating the web request. This should help me debug.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apparently there is some problem using c#'s `WebRequest.Create()` so i changed it to use `HttpClient.PostAsync()` and it worked. Very odd that this stopped working, maybe I changed it at some point and forgot for some reason.
This issue is now resolved, thakns for your help @Andy Heinzer!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for posting your solution here, Devon. If you want to post it again as an Answer, instead of a reply, we can then accept it as the solution to this problem. In turn that might help other users that might encounter the same problem in the future find this post easier.
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.