You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I am a Java developer :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This solution no longer works:
{"errorMessages":["The query parameter 'username' is not supported in GDPR strict mode."],"errors":{}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.