Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,778
Community Members
 
Community Events
185
Community Groups

How to get userid by email using API?

Hello,

I am developing an Application that creates Issues in Jira, and I need to get the username of the current user by email. 

I already found this. When I open this query in my browser, for example:

https://jira.mycompany.de/rest/api/2/user/search?username=email@mycompany.de

this works fine, but only while I am logged in in Jira. 

However, 

when I try to use this in my code, it returns no result.

var url = "https://jira.mycompany.de/rest/api/2/user/search?username=" + email;
var result = new WebClient().DownloadString(url);

I know that this resource cant be accessed anonymously, as stated in the documentation.

How can I do this programmatically? 

 

2 answers

1 accepted

1 vote
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 01, 2018

You would need to pass the Authorizaiton header to your request. You can read more here:

https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/

Go to the Supplying basic auth headers part.

Could you show me an example on how to use this in C#?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 01, 2018

Sorry, I am a Java developer :)

Nevermind, I was able to figure it out myself :)

 Here is what I did, in case anyone might need it in the Future. 

 var url = "https://jira.mycompany.de/rest/api/2/user/search?username=" + email;

string header = "Username:Password";

string encoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(header));

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Authorization", "Basic " + encoded);
request.PreAuthenticate = true;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
var result = reader.ReadToEnd();
}

 

Thank you for your assistance :)

Like # people like this

Finally working. Thanks

This solution no longer works: 

{"errorMessages":["The query parameter 'username' is not supported in GDPR strict mode."],"errors":{}}

Suggest an answer

Log in or Sign up to answer