Hello every posters,
This worked:
$token = 'You token'
$domainname = 'http://localhost/moodle';
$functionname = 'core_course_create_courses';
$restformat = 'json';
//crear objeto de acuerdo a la estructura para crear Categoría en Moodle
$curso = new stdClass();
$curso->fullname = 'Gilberto Mangones';
$curso->shortname ='Gm'; // This data no repeat in other side is inique
$curso->idnumber = 27; // Remember is a consecutive, you problem was for that, you sould write a number
$curso->visible = 1;
$curso->categoryid = 6; // write number of category (1: Misellaneus)
$modulos = array($curso);
$params = array('courses' => $modulos);
header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname;
require_once(APPPATH . 'libraries/curl.php');
$curl = new curl;
$restformat = ($restformat == 'json') ? '&moodlewsrestformat=' . $restformat : '';
$resp = $curl->post($serverurl . $restformat, $params);
return $resp;