I started by following the example set in: https://github.com/moodlehq/sample-ws-clients/blob/master/PHP-REST/client.php but changing the following CurL/XML lines:
$restformat = 'xml'; //Also possible in Moodle 2.2 and later: 'json'
require_once('./curl.php');
$curl = new curl;
$resp = $curl->post($serverurl . $restformat, $params);
for these Unirest/Json lines:
$restformat = 'json';
$resp = UnirestRequest::post($serverurl . $restformat, $headers, $params);
and I received an error "Notice: Array to string conversion", allegedly because of the parameters going in the body. So, I figured I had to serialize the body before sending it, but when I tried:
$response = UnirestRequest::post($serverurl . $restformat, $headers, json_encode($params));
I got back from Moodle:
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Detectado valor de par\u00e1metro no v\u00e1lido","debuginfo":"Missing required key in single structure: users"} ◀"
There must be something I'm not understanding about how exactly the request must look like. Any suggestion?