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.
Finally working. Thanks
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.