Problems using REST API with PHP

Hi

I am currently evaluating youtrack.  A critical item for us is to import many thousands of existing items from one system (Fortress) to youtrack.  I have youtrack up and running in the office just fine.

I have created a php script to connect to the REST API.  I can login, but if i then immediately ask for hte current user, it defaults me back to 'guest'.  I am sure I will need root access to create 15,000 items.

Additionally, it reports no projects, but I know there are some in youtrack

<?php

// Get the curl session object

$session = curl_init();

curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Tell curl not to return headers, but do return the response

curl_setopt($session, CURLOPT_HEADER, false);

// LOGIN

echo "Logging in...\n";

$xml = 'login=root&password=38GuthrieSt';

$url = "http://build2.fugro/youtrack/rest/user/login?";

curl_setopt($session, CURLOPT_URL, $url);

  // Tell curl to use HTTP POST

curl_setopt ($session, CURLOPT_POST, true);

// Tell curl that this is the body of the POST

curl_setopt ($session, CURLOPT_POSTFIELDS, $xml);

$response = curl_exec($session);

echo $response."\n";

//GET THE CURRENT USER

echo "Getting the current user...\n";

curl_setopt($session, CURLOPT_HTTPGET, true);

$url =  'http://build2.fugro/youtrack/rest/user/current';

curl_setopt($session, CURLOPT_URL, $url);

//$session = curl_init($url);

//curl_setopt($session, CURLOPT_HEADER, false);

//curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($session);

echo $response."\n";

//GET A LIST OF PROJECTS

echo "Getting a list of projects in youtrack...\n";

curl_setopt($session, CURLOPT_HTTPGET, true);

$url = "http://build2.fugro/youtrack/rest/project/all";

curl_setopt($session, CURLOPT_URL, $url);

$response = curl_exec($session);

echo $response."\n";

curl_close($session);

?>

Here is my output...
C:\development\php>php -f dummp.php
Logging in...
<login>ok</login>
Getting the current user...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><user fullName="guest"/>
Getting a list of projects in youtrack...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><projects></projects>
C:\development\php>
as you can see, the login reports ok, but it then immediately tells me I am guest.  I imagine this is why I cannot see any projects?
regards
3 comments
Comment actions Permalink

Hi

I managed to sort out the issue.  I needed to persist the returned cookie, and re-use it.

works a treat now (well sort of)

many thanks.

0
Comment actions Permalink

Yep, you're right we identify user by principal cookie that is set by login REST API call and should be passed with all following calls. Also we created Python library for our REST import API and already implemented issue import from Google Code to YouTrack and YouTrack to YouTrack. You can use these scripts as a reference import implementation.

http://confluence.jetbrains.net/display/YTD2/Python+Client+Library

0
Comment actions Permalink

Hi

i did review your python script, but I needed to use php, as this works within our mediawiki.

It is all working now.  A bit of PHP and you can do wonders;-)

regards

0

Please sign in to leave a comment.