The Elearning Community • API - createuser
Page 1 of 1

API - createuser

Posted: Wed Mar 09, 2022 3:08 pm
by BiscottiZA
Hi,

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]+;)/', '&amp;', $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();	
}
?>

Re: API - createuser

Posted: Wed Mar 09, 2022 3:31 pm
by alfa24
Why are you "preg_replace"-ing the api call?
What's the dump of your $apiResults?

Re: API - createuser

Posted: Thu Mar 10, 2022 11:11 am
by BiscottiZA
Hi,

Like I said, some of the code was given to me and works fine for testing the API until I add _customfields.

Re: API - createuser

Posted: Thu Mar 10, 2022 11:25 am
by alfa24
Provide the requested dump, thank you.

This site uses cookies.

Some of the cookies we use are essential for parts of the site to operate and have already been set. We also use Google Analytics scripts, which all use cookies.
You may delete or block all cookies from this site in your browser options.