Let me start by saying the below code is based on help I received in the past from people on this forum.
I have been using FormaLMS APIs to register(user/createuser) and update(user/updateuser) learners without any problems.
I am now trying to include additional fields using the above APIs without success.
Can somebody please look at my “user/createuser” code below and point me in the right direction.
As soon as I remove the line with the '_customfields' from the code below everything works.
I am still learning PHP and I am sure I made a mistake somewhere.
Code: Select all
<?php
header("Content-type: text/xml");
require_once('class.formarestapi.php');
$ApiCall = new FormaRestAPI();
$api_user_name = '';
$api_user_pwd = '';
$url = 'https://www.formalms.com/'; //Base url
$api_key = 'key_value';
$secret_key = 'secret_key_value';
$apiauth = new SimpleXMLElement($ApiCall->call('auth/authenticate', array('username'=>$api_user_name,'password'=>$api_user_pwd), $url, $api_key, $secret_key));
$apitoken = $apiauth->token;
$data_params = array(
'userid' => 'jane',
'firstname' => 'Jane',
'lastname' => 'Doe',
'password' => 'jane',
'email' => 'jane@email.com',
'role' => 'user',
'valid' => 1,
'force_change' => 1,
'_customfields' => [1 => '1249', 3 => '010 445 2011', 4 => 'Sales'],
'auth'=>$apitoken
);
$txtapiresult=preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $ApiCall->call('user/createuser', $data_params, $url, $api_key, $secret_key));
$apiResults = new SimpleXMLElement($txtapiresult);
if (isset($apiResults->success) && $apiResults->success == true)
{
echo $apiResults->asXML();
}
else
{
echo $apiResults->asXML();
}
?>