Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I connect to JIRA Rest API from c #

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 Community Leader Jun 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.

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
Community showcase
Published in Trello

🏊‍♀️ Atlympic Event: Trello

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

34 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you