The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Prince Nyeche - ELFAPP
Atlassian Partner
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 - ELFAPP , 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

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events