Api user/create with _customfields fails

Backend functionalities: user management, course management, reports, certificates, etc.
Post Reply
fdougnac
Newbie
Posts: 6
Joined: Tue Nov 03, 2020 8:11 pm

Api user/create with _customfields fails

Post by fdougnac »

Hello, I am using the api to create users and I have problems with the _customfields
It does not recognize these values ​​when creating the user
I do it this way:

$testApiCall = new SimpleXMLElement(FormaLMS::call('user/create', array(
'auth'=>$tokenforma,
'userid' => ‘user1’,
'firstname' => 'firstuser',
'lastname' => ‘userlast’,
'password' => 'prueba1',
'email' => ‘correo@gmail.com’,
'role' => "user",
'valid' => 1,
'force_change' => 0,
'_customfields' => [
5 => 'customfield5' ,
16 => ‘customfield16’
]
)));
alfa24
Senior Boarder
Posts: 2009
Joined: Fri Nov 24, 2017 8:45 am

Re: Api user/create with _customfields fails

Post by alfa24 »

Other users found this bug. I solved in a custom instance, it's not simple because customfields should be decoded when passed as array in POST (multidimensional arrays cannot be passed as POSTFIELDS parameter when called in a cURL).
One solution is to use http_build_query to encode customfield array.
This would work for createuser and updateuser actions.
If you need help with code, you can contact me in private.
Per supporto GRATUITO contattatemi in privato qui
Post Reply