I have this piece of code where I am trying to get details of a Jira ticket. The HttpResponseMessage always return Un-Authorized. My Jira is a SSO based authentication, so I don't have a username so I have tried with user-name@domain.com too, but no luck.
string url = String.Format("{0}rest/api/2/issue/{1}", "https://abc.atlassian.net/", "PROJ-001");
HttpClient client = new HttpClient();
client.BaseAddress = new System.Uri(url);
byte[] cred = Encoding.ASCII.GetBytes("user-name:password");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage messge = client.GetAsync(url, HttpCompletionOption.ResponseContentRead).Result;
if (messge.IsSuccessStatusCode)
{
string result = messge.Content.ReadAsStringAsync().Result;
details = result;
}
return details;
Language : C#
Status Code : System.Net.HttpStatusCode.Unauthorized
Finally got it working. Answer by Sharoon helped : https://community.atlassian.com/t5/Jira-questions/JIRA-Rest-API-authentication-always-returns-401-unauthorized/qaq-p/187181
The username IS the full email.
The password is NOT your password to login, but an API token. To generate an API token, go to https://id.atlassian.com/manage/api-tokens# and create a new one.
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.