I'm attempting to access the YouTrack REST API via PHP-initiated posts, instead of from Javascript and I'm effectively going no where.

Does anyone have a working example of logging in and then creating a new issue? I can get the login to work correctly but then I can't get it to correctly re-use the session that the login returns.
Comment actions Permalink
Hello Robert,

Thank you for your request.
Actually, that's more about PHP then our REST API. However, I guess you may provide us with your code sample, and YouTrack users or someone from our team will help you.

Thank you.
Comment actions Permalink
RestAPI via PHP

$url = '';
$data = array('login'=>'MyLogin', 'password'=>'somePassword');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data),
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

echo '<br><br>';

The result is something like:

string(17) "ok"

array(9) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(25) "Server: Apache-Coyote/1.1" [2]=> string(21) "Vary: Accept-Encoding" [3]=> string(75) "Set-Cookie: YTJSESSIONID=51704EEC5E8B2460347F60FF5E30250E; Path=/; HttpOnly" [4]=> string(205) "Set-Cookie:; Expires=Sat, 20-Jun-2015 19:27:57 GMT; Path=/" [5]=> string(64) "Cache-Control: no-cache, no-store, no-transform, must-revalidate" [6]=> string(43) "Content-Type: application/xml;charset=UTF-8" [7]=> string(35) "Date: Fri, 20 Jun 2014 19:27:57 GMT" [8]=> string(17) "Connection: close" }

I've tried to do a few things with either (or both) of the Set-Cookie response headers...but without much success. Obviously the login is successful...but the problem is how to do the next POST request which will - say - create a new issue somewhere.

Please sign in to leave a comment.