YouTrack Rest API Web Exceptions
I am having an issue with using the REST API and I am not sure whether the problem lies in the web requests or my use of the API. I am trying to get a list of all the issues for the given sprint:
When I run this code, I receive a "401 Unauthorized" error. However, taking that same URI and pasting it into my web browser works fine with the same username and password. However, I can preform other requests, such as "rest/issue/Issue-1" using the same code as above with no errors.
So, do I need elevated user permissions to run a project related method or is there an error in my request?
Code
var loginRequest = WebRequest.Create( url + "login?" );
loginRequest.Credentials = new NetworkCredentials( user, pw );
var loginResponse = loginRequest.GetResponse();
var authRequest = WebRequest.Create( url + "/rest/project/issues?filter=Sprint:{" + name + "}" );
authRequest.Headers.Add( HttpRequestHeader.Cookie, loginResponse.Headers["Set-Cookie"] );
var authRespose = authRequest.GetResponse();
When I run this code, I receive a "401 Unauthorized" error. However, taking that same URI and pasting it into my web browser works fine with the same username and password. However, I can preform other requests, such as "rest/issue/Issue-1" using the same code as above with no errors.
So, do I need elevated user permissions to run a project related method or is there an error in my request?
Please sign in to leave a comment.
Could you please provide us with your natural REST request (you can look at it thru FireBug) ?
I assume that this code causes wrong result:
var loginRequest = WebRequest.Create( url + "login?" );
loginRequest.Credentials = new NetworkCredentials( user, pw );
var loginResponse = loginRequest.GetResponse();
Thank you,
Waitig for details from you.
However, that code does work depending on the request I send, as I said above. For example:
This works:
This does not:
var loginRequest = WebRequest.Create( url + "login?" ); loginRequest.Credentials = new NetworkCredentials( user, pw ); var loginResponse = loginRequest.GetResponse(); var authRequest = WebRequest.Create( url + "/rest/project/issues?filter=Sprint:{" + name + "}" ); authRequest.Headers.Add( HttpRequestHeader.Cookie, loginResponse.Headers["Set-Cookie"] ); var authRespose = authRequest.GetResponse();We need to review initial rest request. It'll be great if it's possible to provide us with this details.
Thank you,
Waiting for details from you.
Why I need this header for some requests and not others I do not understand. However, my problem is fixed, so I am fine.