403 Forbidden on POST version, PUT has no problem

Devon Lehman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 5, 2018

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? 

2 answers

1 accepted

1 vote
Answer accepted
Devon Lehman February 21, 2019

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!

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 7, 2018

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.

Devon Lehman February 13, 2019

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.

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 15, 2019

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.
Which could mean that your request is not authenticated as expected OR your account doesn't have rights to do so.
I'm somewhat confused by your ability to use PUT to that endpoint solely for creating versions.  I don't think that should work, unless you're also including the version ID number at the end of the endpoint URL, in order to edit that version via REST, such as explained in PUT /rest/api/2/version/{id}
That related endpoint can use the PUT verb in order to changed/edit versions.
I have not been able to replicate the reported behavior here.  But I am interested to learn more about this setup, and your environment to see if we can figure out what might be the exact cause of this 403 error.
Devon Lehman February 15, 2019

> Interested to learn more

What information I can give you that would help debug this?

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 19, 2019

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?

Devon Lehman February 19, 2019

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.

Devon Lehman February 19, 2019

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!

Like Andy Heinzer likes this
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 21, 2019

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.

Suggest an answer

Log in or Sign up to answer