LMSouq
general-dev Open

Cannot assign role to user using web service

AK
Akhilesh
1 month ago
3 views
Problem Description
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"}

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base