I am trying to update status of an issue in JIRA using C# code. I found various curl codes for the same, but since I am unfamiliar to curl, I converted the code to C#.
Now, the first error I am facing is "Status code: 401", "Unauthorized". I am using email and API token to authorize. Searched and read through all the blogs/questions, found very similar issues but unable to figure out the issue with my code.
Also I am new to C# and Jira environment, it would be great if you could help me out with finding the error. Or if I am missing something in the code?
See code below:
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("PUT"), "https://<myhostname>.atlassian.net/rest/api/2/issue/<project>-<issueno>"))
{
var username = "<my-email>";
var password = "<API Token>";
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");
request.Content = new StringContent("{\"transition\":{\"id\":\"11\"}}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await httpClient.SendAsync(request);
Console.WriteLine(response);
}
}
Thanks
Bhawna