2

I am trying to assign a role using webservice. I have tried the below code to assign the role.

$user_id= 35;
$context_id=1;
$role_id=5;


$assignment = array( 'roleid' => $role_id, 'userid' => $user_id, 'contextid' => $context_id );
$assignments = array( $assignment );
$params = array( 'assignments' => $assignments );
$functionname = 'core_role_assign_roles';

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
$response = $curl->post( $serverurl . $restformat, $params );

print_r( $response );

when I run the code, I am getting the below respone. Please help.

{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected","debuginfo":"Can not assign roleid=5 in contextid=1"}
Akhilesh
  • 1,243
  • 4
  • 16
  • 49

1 Answers1

1

It worked after I added the roles to 'Allow role assignments' option in edit role page.

Akhilesh
  • 1,243
  • 4
  • 16
  • 49