Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.