problems with the ActiveResource.php
Added by Andreas Schrottenbaum over 14 years ago
Hi,
I am about to find a solution to create new Tickets from a website written in PHP and found this article:
http://www.redmine.org/wiki/1/Rest_api_with_php
I've done everything how it's explained, but it won't work as expected.
My Code:
<?php
require_once ('ActiveResource.php');
class Issue extends ActiveResource {
var $site = 'http://admin:admin@127.0.0.1:3000/';
var $request_format = 'xml'; // REQUIRED!
}
// create a new issue
$issue = new Issue (array ('subject' => 'XML REST API', 'project_id' => '1'));
$issue->save ();
echo $issue->id;
?>
The result:
Notice: Undefined offset: 1 in /var/www/redTest/ActiveResource.php on line 345
Notice: Undefined property: Issue::$id in /var/www/redTest/ActiveResource.php on line 472
Replies (4)
RE: problems with the ActiveResource.php - Added by Felix Schäfer over 14 years ago
I'm not familiar with PHP, but let's tackle the other side of the issue: your redmine installation is recent enough for the issue REST API to be in there, and you have activated the REST API in the redmine settings?
RE: problems with the ActiveResource.php - Added by Andreas Schrottenbaum over 14 years ago
My configuration:
Ruby version: Redmine 0.9.4.devel (MySQL)
Rails version: 2.2.3-2
Operating system: Ubuntu 10.4
Database used: mySQL 5.1.41
Ruby-aware server used: Webrick
I also just realized, that this is written in the log:
Processing IssuesController#create to xml (for 127.0.0.1 at 2010-07-23 11:41:06) [POST]
Parameters: {"format"=>"xml", "action"=>"create", "issue"=>{"project_id"=>"1", "subject"=>"XML REST API"}, "controller"=>"issues"}
Filter chain halted as [:authorize] rendered_or_redirected.
Completed in 11ms (View: 0, DB: 1) | 401 Unauthorized [http://127.0.0.1/issues.xml]
RE: problems with the ActiveResource.php - Added by Andreas Schrottenbaum over 14 years ago
Thank you Felix.
I missed to activate the Checkbox in the ACP. Shame on me
RE: problems with the ActiveResource.php - Added by Felix Schäfer over 14 years ago
Ok, several things:
- The issue REST API is not in 0.9.x, you will need a recent-ish trunk or the 1.0.0RC,
- Redmine 0.9.x and 1.0.x needs rails 2.3.5 (though if you have installed the redmine package from Ubuntu, it has some patches to make it work with older rails versions),
- The MySQL gem is AFAIK only compatible with MySQL up to 5.0.x, you might get weird errors there (though several people seem to use 5.1 and are happy with it, YMMV).