bulk import issues using PHP problem with REST API
Hi, as per your suggestions, I am trying to use the import issues method in the REST API. For various reasons, I am using PHP (primarily as I have a large code base in php to connect to our existing systems, wiki etc)
the trouble is I cannot get this one method to work. All of the other REST api is fine. It is this one method...
"/rest/import/NG/issues";
<?php
puttest ("http://build2.fugro/youtrack", "root", <mypassword>);
function puttest ($baseURL, $user, $password)
{
$session = curl_init();
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($session, CURLOPT_COOKIEFILE, "cookiefile");
curl_setopt($session, CURLOPT_VERBOSE, TRUE);
// LOGIN
$params = "login=" . $user . "&" . "password=" . $password;
$url = $baseURL . "/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, $params);
$response = curl_exec($session);
echo $response . "\n";
//so far so good....
$url = $baseURL . "/rest/import/NG/issues";
$filesize = filesize ('sampleissue.xml');
//a sample file from jetbrains
$xml = file_get_contents('sampleissue.xml');
//echo $xml;
echo $url . "\n";
$file = tmpfile();
fwrite($file, $xml);
fseek($file, 0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $file);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($xml));
$result = curl_exec($ch);
fclose($file);
curl_close($ch);
echo $result;
}
?>
I took your sample XML file as a basis (attached)
the output I get is....
C:\Temp>"c:\Program Files (x86)\php"\php -f puttext.php
* About to connect() to build2.fugro port 80 (#0)
* Trying 172.23.21.2... * connected
* Connected to build2.fugro (172.23.21.2) port 80 (#0)
> POST /youtrack/rest/user/login? HTTP/1.1
Host: build2.fugro
Accept: */*
Content-Length: 31
Content-Type: application/x-www-form-urlencoded
< HTTP/1.1 200 OK
< Content-Type: application/xml;charset=UTF-8
< Server: Microsoft-IIS/7.0
* Added cookie JSESSIONID="DE63BCEDBC6ED248C8D8AA4A7FEA9A3D" for domain build2.f
ugro, path /youtrack, expire 0
< Set-Cookie: JSESSIONID=DE63BCEDBC6ED248C8D8AA4A7FEA9A3D; Path=/youtrack
* Added cookie jetbrains.charisma.main.security.PRINCIPAL="NDMwZWE0N2M0MzNhYmY5M
jU2YjllMTZkZjg3MDAyY2UyOWEzODY2NGI4NzA3NDMyOWEwYzkyNGE2NmMyMjVjNzpyb290" for dom
ain build2.fugro, path /youtrack, expire 1329233503
< Set-Cookie: jetbrains.charisma.main.security.PRINCIPAL=NDMwZWE0N2M0MzNhYmY5MjU
2YjllMTZkZjg3MDAyY2UyOWEzODY2NGI4NzA3NDMyOWEwYzkyNGE2NmMyMjVjNzpyb290; Expires=T
ue, 14-Feb-2012 15:31:43 GMT; Path=/youtrack
< X-Powered-By: ASP.NET
< Date: Mon, 14 Feb 2011 15:31:42 GMT
< Content-Length: 17
<
* Connection #0 to host build2.fugro left intact
<login>ok</login>
http://build2.fugro/youtrack/rest/import/NG/issues
<html><head><title>Apache Tomcat/6.0.26 - Error report</title><style><!--H1 {fon
t-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:
22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525
D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;backgro
und-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;col
or:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:w
hite;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;backgroun
d:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR
{color : #525D76;}--></style> </head><body><h1>HTTP Status 415 - </h1><HR size="
1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></
p><p><b>description</b> <u>The server refused this request because the request e
ntity is in a format not supported by the requested resource for the requested m
ethod ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.26</h3></b
ody></html>1* Closing connection #0
C:\Temp>
I have been on this for a few days, and it is completely driving me nuts
regards
Attachment(s):
puttext.php.zip
sampleissue.xml
Please sign in to leave a comment.
Hi, just to follow up, I had a look at your youtrack.log file, and I could see the request coming in....
15 Feb 2011 12:53:02,564 INFO [MainServlet ] [http request: /rest/user/login ] Start processing request /rest/user/login
15 Feb 2011 12:53:02,564 DEBUG [BaseApplication ] [http request: /rest/user/login ] Created bean for session variables
15 Feb 2011 12:53:02,567 INFO [MainServlet ] [http request: /rest/user/login ] Finish processing request /rest/user/login in 2ms
15 Feb 2011 12:53:02,578 INFO [MainServlet ] [http request: /rest/import/NG/issues ] Start processing request /rest/import/NG/issues
15 Feb 2011 12:53:02,578 INFO [MainServlet ] [http request: /rest/import/NG/issues ] Finish processing request /rest/import/NG/issues in 0ms
Can you provide the full HTTP request you are sending when importing issues? I mean request with headers and so on, because such message can apear f.e. if you are using wrong message content type. For PUT method it must be application/xml
Hi
thanks for getting back to me.
I moved this item here, so I can keep all my stuff together...
http://youtrack.jetbrains.net/issue/JT-8239
I have resubmitted with a better test php script in issue 8239.
I will reply there.
please close this item here.
regards