I am trying to update user roles using restws module. Please refer to the code given below:

    $url = "http://DRUPAL_ROOT/user/3";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "restws_test1" . ":" . "password");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
   
    $data = array("roles" => array("3" => 3));

    //I've tried following as alternatives:
    //$data = array("roles" => array("3" => "3"));   
    //$data = array("roles" => array(3 => "3"));
    //$data = array("roles" => array(3 => 3));
   
    $data_string = json_encode($data);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array (
        "Content-Type: application/json",
        "Content-Length: ".strlen($data_string)
    ));

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
   
    $retValue = curl_exec($ch);
    var_dump($retValue);
    curl_close($ch);
   

This code gives me following error:
Recoverable fatal error: Argument 2 passed to RestWSBaseFormat::getResourceReferenceValue() must be of the type array, integer given, called in D:\xampp\htdocs\drupalPractice\drupalTest1\sites\all\modules\restws\restws.formats.inc on line 244 and defined in RestWSBaseFormat->getResourceReferenceValue() (line 277 of D:\xampp\htdocs\drupalPractice\drupalTest1\sites\all\modules\restws\restws.formats.inc).

Any advice on how to solve this issue (even using xml is fine)?

Just for reference, when sending get request, the dump:
In XML:

    <roles>
        <item>2</item>
        <item>3</item>
    </roles>
   

In JSON:

{"roles":[2,3]}

Comments

Fixed, had to pass

Fixed, had to pass array("roles" => array(array("id" => 3)));