Adding users vial REST API

Adding users vial REST API

by Aaron Harker -
Number of replies: 3

I've got an old Moodle 3.8 site we are currently in the process of building a more up to date replacement for.  In the interim I'm trying to automate so of the functions for this old site to give the admins more time to work on the new one.  One of the things I want to do is automate the creation of new users in the Moodle system from our Laravel based SIS.

I've got the webservice setup and can connect to the REST endpoints fine but I seem to be having trouble getting the data in the correct format for Moodle.  I'm using the 'core_user_create_users' endpoint.  I'm formatting my data like this.

['users'=>[
    [
        'username'=> 'test.test',
        'passowrd' => '*****',
        'firstname' => 'test',
        'lastname' => 'test',
        'email'=>'test@test.com',
        'city' => 'Some City',
        'country' => 'Some Country',
        'timezone' => 'some/timezone'
    ]]
]

Can anyone see where I'm going wrong because it is driving me mad.  The error is an 'invalid_parameter_exception' = 'Invalid parameter value detected'

Average of ratings: -
In reply to Aaron Harker

Re: Adding users vial REST API

by romar vadelin -

Hi there, 

i dont know if that is a copy paste of your exact code, but there seems to be a typo

'passowrd' => '*****',

If thats not it .. The complaint is about the parameter, not the values. So check whether or not you provide all the required keys and do not provide any keys that are not required or optional. 

In reply to romar vadelin

Re: Adding users vial REST API

by Aaron Harker -
No it weasn't a copy and paste, I retyped it and made a typo. I'm really not sure why doing it like that didn't work but I ended up defining each level of the array individually and eveything worked.
In reply to Aaron Harker

Re: Adding users vial REST API

by Dee Odee -
Hello,

I'm in the process of doing something similar, but I keep getting an access control exception trying to create users via the API. Would you mind sharing how you were able to set that up?

thanks