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);
}
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"
Hi @Prince Nyeche , yes I have already done that, I havent mentioned it here.
I have done something like following,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.