Invalid-parameter errorr from apparenly valid user and group IDs passed to core_group_add_group_members

Invalid-parameter errorr from apparenly valid user and group IDs passed to core_group_add_group_members

by Jocelyn Ireson-Paine -
Number of replies: 5
I'm trying to call the core_group_add_group_members Web service, but getting an invalid-parameters message for apparently valid user and group IDs.

I'll show the program at the end of this posting.

If I call it with an invalid group ID but a valid user ID, I get an error with exception class "dml_missing_record_exception", errorcode "invalidrecord", and message "cannot find data record in database table groups".

If I call it with a valid group ID but an invalid user ID, I get an error with exception class "dml_missing_record_exception", errorcode "invaliduser", and message "invalid user".

The fact that it can detect invalid groups and users suggests to me that I am calling it correctly.

But when I pass it a valid user ID and a valid group ID, I get the "invalid parameter value detected" exception.

So when the user and group are OK, it seems not to like the format in which I've passed them, or something.

This is my code:

$group_id = 21;

$user_id = 149;

$params = "&members[0][groupid]=" . $group_id . "&members[0][userid]=" . $user_id;

$token = 'bbb86beefd82sttewsdef5fd9ef1b3e7c3';

$url = "my_moodle.com";

$serverurl = $url . '/webservice/rest/server.php?wstoken=' . $token . "&wsfunction=core_group_add_group_members";

require_once( './curl.php' );
$curl = new curl;

$response = $curl->post( $serverurl, $params );

echo "Response = \n", $response, "\n";

Jocelyn

Average of ratings: -
In reply to Jocelyn Ireson-Paine

Re: Invalid-parameter errorr from apparenly valid user and group IDs passed to core_group_add_group_members

by Alfonso Rivero -

Hi Jocelyn,


I'm also having this issue, tried with invalid groupid and userid  returning 

stdClass Object

(

    [exception] => dml_missing_record_exception

    [errorcode] => invaliduser

    [message] => Invalid user

)

When I try existing userid and groupid 

stdClass Object

(

    [exception] => invalid_parameter_exception

    [errorcode] => invalidparameter

    [message] => Invalid parameter value detected

)


did you find a solution?

In reply to Alfonso Rivero

Re: Invalid-parameter errorr from apparenly valid user and group IDs passed to core_group_add_group_members

by Alfonso Rivero -

I've found the solution.

Left the comment here for reference to somebody with the same problem.

To add a member to a group, the user must be enroled in the course the groups belongs to.



In reply to Alfonso Rivero

Re: Invalid-parameter errorr from apparenly valid user and group IDs passed to core_group_add_group_members

by Jordan Sipahutar -

HI Alfonso,

I already enrolled user to course,

I want to add group member using web service,

But, it didn't work,
error message :

 '{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected","debuginfo":"Missing required key in single structure: members"}' 

it is my code:

 public function assign_user_group($userid, $groupid)

    {

       $functionName = 'core_group_add_group_members';

         

        $member = new stdClass();

        $member->groupid = $groupid;

        $member->userid = $userid;

      

        $members = array($member);

        $params = array('$members' => $members);


        /// REST CALL

        $restformat = "json";

        $serverurl = $this->serverUrl . '&wsfunction=' . $functionName . '&moodlewsrestformat=' . $restformat;

        require_once ('curl.php');

        $curl = new curl();

        $resp = $curl->post($serverurl, $params);


        echo '</br>************************** Server Response Assign user to group()**************************</br></br>';

        echo $serverurl . '</br></br>';

        var_dump($resp);   

    }

do you have  solution for this problem?

In reply to Jordan Sipahutar

Re: Invalid-parameter errorr from apparenly valid user and group IDs passed to core_group_add_group_members

by Alfonso Rivero -

Hi Jordan,

I think that you have a "syntax" problem:

$params = array('$members' => $members);

should be:

$params = array('members' => $members);


without '$'






In reply to Alfonso Rivero

Re: Invalid-parameter errorr from apparenly valid user and group IDs passed to core_group_add_group_members

by Jordan Sipahutar -

Thank you Alfonso Rivero,

it's really helpful for me to solved my problem,

smile