REST API Request Problem
Hello,
I have some REST API request problems. If I send a POST request for login, I get the response <200 OK,<login>ok</login>. All is fine. But if I send a GET request to https://myYouTrackServer/rest/issue/issue-ID then I get the following exception:
org.springframework.web.client.RestTemplate handleResponseError
WARNUNG: GET request "https://myYouTrackServer/rest/issue/issue-ID" resulted in 401 (Unauthorized); invoking error handler
With http://localhost:port/rest/issue/issue-ID I get the same exception.
My workaround for this problem is to change the response-cookie:
Original Cookie-String: [YTJSESSIONID=w9p8jn37btl2fpig94pm63eb;Path=/, jetbrains.charisma.main.security.PRINCIPAL=ZDhhYjU3ZWEwYmJhOTA4NWNkOTlhZWJmMGY1YzhjN2NkMWE1MzI5YTVhYmM0MWE3M2E5MDllNmMxNWEwNjZmZDpyb290;Path=/;Expires=Wed, 18-Nov-2015 08:56:46 GMT]
Modified Cookie-String: YTJSESSIONID=w9p8jn37btl2fpig94pm63eb;Path=/, jetbrains.charisma.main.security.PRINCIPAL=ZDhhYjU3ZWEwYmJhOTA4NWNkOTlhZWJmMGY1YzhjN2NkMWE1MzI5YTVhYmM0MWE3M2E5MDllNmMxNWEwNjZmZDpyb290;Path=/;Expires=Wed, 18-Nov-2015 08:56:46 GMT
without the sign "[" at the beginnig "]" and the end.
With this change I get the excepted response.
Possibly the same problem here:
http://forum.jetbrains.com/thread/YouTrack-1640
I have some REST API request problems. If I send a POST request for login, I get the response <200 OK,<login>ok</login>. All is fine. But if I send a GET request to https://myYouTrackServer/rest/issue/issue-ID then I get the following exception:
org.springframework.web.client.RestTemplate handleResponseError
WARNUNG: GET request "https://myYouTrackServer/rest/issue/issue-ID" resulted in 401 (Unauthorized); invoking error handler
With http://localhost:port/rest/issue/issue-ID I get the same exception.
My workaround for this problem is to change the response-cookie:
Original Cookie-String: [YTJSESSIONID=w9p8jn37btl2fpig94pm63eb;Path=/, jetbrains.charisma.main.security.PRINCIPAL=ZDhhYjU3ZWEwYmJhOTA4NWNkOTlhZWJmMGY1YzhjN2NkMWE1MzI5YTVhYmM0MWE3M2E5MDllNmMxNWEwNjZmZDpyb290;Path=/;Expires=Wed, 18-Nov-2015 08:56:46 GMT]
Modified Cookie-String: YTJSESSIONID=w9p8jn37btl2fpig94pm63eb;Path=/, jetbrains.charisma.main.security.PRINCIPAL=ZDhhYjU3ZWEwYmJhOTA4NWNkOTlhZWJmMGY1YzhjN2NkMWE1MzI5YTVhYmM0MWE3M2E5MDllNmMxNWEwNjZmZDpyb290;Path=/;Expires=Wed, 18-Nov-2015 08:56:46 GMT
without the sign "[" at the beginnig "]" and the end.
With this change I get the excepted response.
Possibly the same problem here:
http://forum.jetbrains.com/thread/YouTrack-1640
Please sign in to leave a comment.
Could you please tell how you could login successfully using REST API. Every time I get a bad request 400.
Here is my code. I hope you can help on this:
$.ajax({
url: "my.website.com:8080/rest/user/login",
dataType: "json",
type: "POST",
data: {
login: 'root',
password: 'root'
}
});
Assuming I've youtrack deployed on port 8080 on my.website.com
Also, I was able to post issues if and only if I'm logged in the same browser to my YouTrack account.
Your help is appreciated.
function createIssue(output, status, xhr) {
$.ajax({
url:"http://my.website.com:8080/rest/issue",
dataType:"json",
type:"PUT",
data:{
project:"XYZ",
summary:$("#summary").val(),
description:$("#description").val()
},
xhrFields: {
withCredentials: true
}
}).done(function (data) {
$("#result").show();
$("#summary").val();
$("#description").val();
});
};
function doLogin(){
$.ajax({
url: "http://my.website.com:8080/rest/user/login",
datatype: "application/x-www-form-urlencoded",
type: "POST",
data: {login:'username@domain.com',
password:'password'},
success: createIssue,
xhrFields: {
withCredentials: true
}
}
);
};
All you need to do, is to change the website, project and credentials to match yours. Then call doLogin() function on form submit.
I hope it is helpful for anyone searching how to use YouTrack API to send an issue.