Home /Tutorials/Adding a new client
Adding a new client

In this tutorial, we’ll go through an example that involves two calls when adding a new client to a business.  

The first call will provide a list of fields to be populated for a new client such as name, email, and phone number. Each field and its respective key(s) will need to be identified. We can use the id_field_general value to identify each key. 

// To be used after signing in. 
$o_lead_model = new \WellnessLiving\Wl\Lead\LeadModel($o_config); 
$o_lead_model->cookieSet($o_notepad->cookieGet()); // Keep cookies to keep session. 
$o_lead_model->k_business='3'; 

// Perform the request. 
$o_lead_model->get(); 
foreach($o_lead_model->a_field_list as $a_field) 
{ 
 echo $a_field['k_field'].' '.$a_field['id_field_general'].' '.$a_field['text_field']."\n"; 
} 

Once it’s possible to identify the fields, those fields can be populated with the new client’s information. The POST method is used to create the new client. 

// NotepadModel and EnterModel omitted for brevity. 
$o_lead_model = new \WellnessLiving\Wl\Lead\LeadModel($o_config); 
$o_lead_model->k_business='3'; 

// Perform the request 
$o_lead_model->get(); 
$a_field_general = []; 
foreach($o_lead_model->a_field_list as $a_field) 
 $a_field_general[$a_field['id_field_general']] = $a_field['k_field']; 

// Using k_field => value, create a new client. 
$o_lead_model->a_field_data = [ 
 $a_field_general[WlFieldGeneralSid::NAME_FIRST] => 'First', 
 $a_field_general[WlFieldGeneralSid::NAME_LAST] => 'Last', 
 $a_field_general[WlFieldGeneralSid::LOGIN] => 'First@last.com', 
 $a_field_general[WlFieldGeneralSid::PHONE_CELL] => '123-456-7890' 
]; 
$o_lead_model->post(); 
echo 'User created with uid of '.$o_lead_model->uid."\n";