Can not login Jira with Api

Viewed 261

I have this code below, i need to login but Jira documantation so bad that i cant figured out, how can i login to jira ? They say basic auth is depreced but all examples are like this. How can i login ?

var apiUrl = @"https://MYDOMAIN.atlassian.net/rest/api/3/issue/MYPROJECTNAME";

            using (var httpClient = new HttpClient())
            {
                using (var request = new HttpRequestMessage(new HttpMethod("GET"), apiUrl))
                {
                   request.Headers.TryAddWithoutValidation("Accept", "application/json");

                    var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("xxxxx@gmail.com:1xxxxxk2qdnqHJxxxx155"));
                    request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");

                    var response = await httpClient.SendAsync(request);

                }
            }
1 Answers

You are right, documentation too weak.

In my use cases, I preferred using "username" only. Not email. Can you try this?

var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("<YOUR_USERNAME>:1xzyNAGgksdfgP3155"));

This is Jira documentation:

The username and password of a user who has permission to create issues on your Jira Server site

Build a string of the form username:password.

If this recommendation fails can you share your rest logs?

Related