I'm using ActiveResource to add new projects via PHP to my redmine. Editing/fetching projects works perfectly fine. But adding a new one doesn't seem to work. The REST api returns:
<?xml version="1.0" encoding="UTF-8"?><errors type="array"><error>Name cannot be blank</error><error>Identifier cannot be blank</error><error>Identifier is too short (minimum is 1 characters)</error></errors>
It says the name and identifier are empty, but they aren't since I've added them in my script.
Is my code wrong or is there something else to it?
error_reporting(E_ALL);
require_once ('ActiveResource.php');
class Project extends ActiveResource {
var $site = 'http://redmine/';
var $user = 'admin';
var $password = 'admin';
var $element_name = 'projects';
var $request_format = 'xml'; // REQUIRED!
var $extra_params = '?key=XXXX';
}
$project = new Project(array('name' => 'Tittel', 'identifier' => "shop", 'description' => 'asd'));
var_dump($project);
if ($project->save()) {
echo 'succes';
} else {
echo 'fail';
}
Fixed it myself. The $element_name should be non-plural. Changing it to project did the trick.