无法将角色分配给使用Web服务的用户
问题描述:
我正在尝试使用webservice分配角色。我已经尝试了下面的代码来分配角色。无法将角色分配给使用Web服务的用户
$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);
当我运行代码时,我得到了下面的答案。请帮忙。
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected","debuginfo":"Can not assign roleid=5 in contextid=1"}
答
它在编辑角色页面中将角色添加到'允许角色分配'选项后工作。