API - createuser

Install and configure FormaLMS and DoceboCE
Post Reply
BiscottiZA
Newbie
Posts: 5
Joined: Wed Jul 28, 2021 7:00 am

API - createuser

Post 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();	
}
?>
alfa24
Senior Boarder
Posts: 2008
Joined: Fri Nov 24, 2017 8:45 am

Re: API - createuser

Post by alfa24 »

Why are you "preg_replace"-ing the api call?
What's the dump of your $apiResults?
Per supporto GRATUITO contattatemi in privato qui
BiscottiZA
Newbie
Posts: 5
Joined: Wed Jul 28, 2021 7:00 am

Re: API - createuser

Post 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.
Last edited by BiscottiZA on Fri Mar 11, 2022 6:00 am, edited 2 times in total.
alfa24
Senior Boarder
Posts: 2008
Joined: Fri Nov 24, 2017 8:45 am

Re: API - createuser

Post by alfa24 »

Provide the requested dump, thank you.
Per supporto GRATUITO contattatemi in privato qui
Post Reply