Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I was unable to get the result when try to hit JIRA REST API

Vamsi June 12, 2018

I am trying to hit API from C# code using HTTP client but I am getting the result as unauthorized. If I try with postman it's working fine. what will the issue ?

2 answers

0 votes
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2018

Hi Vamsi

My C# application has the following 2 lines before the Convert.ToBase64String :

string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
return Convert.ToBase64String(byteCredentials);

Try to see if that helps

Vamsi June 12, 2018

Thanks Warren for responding.

I am getting the AuthCredentials in the perfect way. I think it's problem with the permissions. Do we need to enable any permission ?

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Hi Vamsi

If I'm correct, the call you're doing (https://hrbotdev.atlassian.net/rest/api/latest/issue) isn't valid, because it needs a further /ABC-123 passing in the issue key.

I tried your call but with my Jira name instead of hrbotdev and I received an error. I added a key and it worked, so I think you need

https://hrbotdev.atlassian.net/rest/api/latest/issue/ABC-1234

Vamsi June 13, 2018

Yeah, that is for getting the issue which has been already created. I want create the issue using the API.

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2018

Hello,

It mean you provide invalid credentials or you do not provide credentials at all.

Vamsi June 12, 2018

No, I am giving the creadentials.

string authCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(Username + ":" + Password));
client.DefaultRequestHeaders.Add("Authorization", "Basic " + authCredentials);
client.DefaultRequestHeaders.Add("Accept", "application/json");
var result = JsonConvert.SerializeObject(model);
var response = await client.PostAsync($"https://hrbotdev.atlassian.net/rest/api/latest/issue", new StringContent(result, Encoding.UTF8, "application/json"));

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2018

Could you somehow to see, what request is sent from your program? I usually use Fiddler for it.

Vamsi June 12, 2018

It's working in postman fine. In program only it's not working

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2018

It means that your request, which is sent from your program, is different from postman. You need to see your request.

Vamsi June 12, 2018

No, both are same. The following is the API

https://hrbotdev.atlassian.net/rest/api/latest/issue

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2018

If they were same, then the result would be also same 

Vamsi June 12, 2018

I tried with all those, I think it's not problem from coding side. Because when I tried the same request in others system postman, they also got Unauthorized status code. It means when we access it remotely It's not working. Do I need to enable any permission to access it globally in atlassian account ?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2018

No, there is no permissions like this. You said before, that it worked in postman and now it does not work. What is the difference?

Vamsi June 13, 2018

It worked in my system(i.e., in postman). In others system postman request also not working.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events