Forums

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

How can I connect to JIRA Rest API from c #

usuario_dynamics
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!
June 17, 2021

I am making a GET request to a task that exists and I get a 404 Not fund 

this is the code

The baseUrl variable contains the Url of our JIRA.

httpClient.BaseAddress = new Uri(baseUrl);
var requestMessage = new HttpRequestMessage(HttpMethod.Get, "rest/api/3/issue/pijd-7");
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", basicAuth);
var response = await httpClient.SendAsync(requestMessage);
var str = await response.Content.ReadAsStringAsync();

1 answer

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 18, 2021

Hi @usuario_dynamics 

Given that you're getting a 404, I'm assuming that your authentication is working.

The screenshot below is from the documentation.

Screenshot_1.jpg

To confirm that you have access to the issue, with Jira open in a browser window, open another tab and combine your baseURL with rest/api/3/issue/pijd-7 and confirm that it returns the issue details correctly.

Have you tried any other API calls? Try using /rest/api/3/search with no parameters, which should prove (or disprove) that all your other code is working correctly.

Finally, you could try using Postman (either the web based one or downloading it) which takes the element of your C# code out of it. 

It definitely is possible to use the API with C# code, I've been doing it for years now.

usuario_dynamics
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!
June 18, 2021

Hi Warren,
Thank you very much for answering, all the tips that you tell me I had done.
I have solved the problem by changing several things in the code, this is the new code

using (var request = new HttpRequestMessage (new HttpMethod ("GET"), baseUrl + "/ rest / api / 3 / issue / 59998"))
{
request.Headers.TryAddWithoutValidation ("Accept", "application / json");

var base64authorization = Convert.ToBase64String (Encoding.ASCII.GetBytes (email + ":" + token));
request.Headers.TryAddWithoutValidation ("Authorization", $ "Basic {base64authorization}");
}
1. The last parameter of the url before had the name of the issue and I have changed it to the id
2. I have changed the header of the message.
3. The way to format the authentication string.
With these changes everything works correctly.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events