Saving Category through API I'm trying to create a category through the api to import a load of datas,
but I'm stuck, the category won't be saved, and the saveCategory() method just returns false  

$category = new CategoryModel();
$category-&gt;setContentFromPost(array(
    'groupId'       =&gt;  $this-&gt;category_group_id,
    'title'         =&gt;  $data[0],
    'colorCode'     =&gt;  $data[1],
    'colorPreview'  =&gt;  $data[2]
));
$category-&gt;enabled = true;
$res = craft()-&gt;categories-&gt;saveCategory($category);


Can I get a glimpse of what's happening, or the error ?

Is there anything wrong in this code ?
Does anyone have a good example/documentation for this ?

Thanks for your help.

Nicolas
You can get any validations errors on the category after you've attempted to save it with CategoryModel::getAllErrors() or \CModel::getErrors(). 

You're also setting the groupId on the Category's ContentModel, but this property is actually on the Category record itself as it sets the relationship directly.

$category = new CategoryModel();
$category-&gt;groupId = $this-&gt;category_group_id;

$category-&gt;SetContentFromPost(array(
    'title' =&gt; $data[0],
    'colorCode' =&gt; $data[1],
    'colorPreview' =&gt; $data[2],
));

if (craft()-&gt;categories-&gt;saveCategory($category))
{
    return true;
}
else
{
    // dump the error messages
    Craft::dd($category-&gt;getAllErrors());
}