Project

General

Profile

API Rest via PHP

Added by Oleg Belov about 13 years ago

Hello! Does anybody know, does it work?
Now, I'm trying to send issues via php.
I'd found all information such:
http://www.redmine.org/projects/redmine/wiki/Rest_api
http://www.redmine.org/projects/redmine/wiki/Rest_api_with_php

But it doesn't work...
First, I've found ActiveResource.php (don't remember where)
and write index.php:
@@
if (! extension_loaded ('curl')) {
echo 'cURL extension not loaded.';
exit();
}

require_once ('ActiveResource.php');
class Issue extends ActiveResource 
{
// echo base64_encode("belov:123456");
var $site = 'http://belov::3000/issues';
var $request_format = 'xml'; // REQUIRED!
}

$issue = new Issue (array ('subject' => 'XML REST API', 'project_id' => '1'));
$issue->save ();
echo $issue->id;
@@

But I got the mistake. Redmine said, that ther are no Content-length but redmine need it...

I rewrote ActiveResource.php like this:
curl_setopt ($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/x-www-form-urlencoded", "Content-length: ".strlen($params)));
instead this:
curl_setopt ($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/x-www-form-urlencoded"));

Well. Redmine accepted the XML, but I've got internal serve Error 500 with this log:
Processing IssuesController#create to xml (for 10.10.0.4 at 2011-02-03 10:23:42) [POST]
Parameters: {"format"=>"xml", "project_id"=>"1", "action"=>"create", "subject"=>"XML REST API", "controller"=>"issues"}
Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json).

I was playing with headers (like "text/xml", "application/xml" and other) but it didn't help.
It seams, that it can't athorise with my login|password.
Via C# I can connect and send the new issue. It's no problem, but I need to realise it via PHP.

Anybody, help!