Forums

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

Getting response error (400) when contacting REST API through JIRA API TOKEN

Suhas Shirsat
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!
August 17, 2020

I am trying to make REST API GET call on JIRA cloud using API tokens. I tried different codes but I am keep getting the same 400 error. In browser session API call works fine. 

Following is my C# code , can someone tell me what I am doing wrong.

var url = new Uri("https://mysite.com");

var httpClient = new HttpClient(new HttpClientHandler(){})
{
BaseAddress = url,
Timeout = new TimeSpan(0, 2, 0)
};

httpClient.DefaultRequestHeaders.Add("ContentType", "application/json");
httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + GetEncodedCredentials());

var result = await httpClient.GetAsync(url);

if (result.IsSuccessStatusCode)
{
var response = await result.Content.ReadAsStringAsync();
}

---------------

private string GetEncodedCredentials()
{
string mergedCredentials = string.Format("{0}:{1}", "myid@abc.com", "API TOKEN");
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
return Convert.ToBase64String(byteCredentials);
}

1 answer

0 votes
Prince Nyeche
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.
August 17, 2020

Hi @Suhas Shirsat 

I'm not particularly familiar with C# but if you're connecting to Jira Cloud, you have to specify the endpoint literally. e.g. "/rest/api/3/project"

Suhas Shirsat
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!
August 17, 2020

Hi @Prince Nyeche , yes I have already done that, I havent mentioned it here.

I have done something like following,

https://mysite.com/rest/api/3/issue/10662

Suggest an answer

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

Atlassian Community Events