How to create a new contact in Toky

Create contacts in Toky's phone directory to be used with the caller Id

Toky's phone directory is used by our virtual phone system to identify callers, and you can use this function to create contacts from your software in Toky.

📘

API Endpoint used

/contacts

Parameters you need to replace in the getTokyContacts function:

❗️

Phone number must be unique

You can't create several contacts with the same phone number.

<?php

function createContact($phoneNumber, $created_by,$first_name,$last_name,$email){
    // create a new cURL resource
    $ch = curl_init();
    $api_key = '[[TOKY_API_KEY]]';
    $headers = array();
    $headers[] = "X-Toky-Key: {$api_key}";

		$data = array("number" => $phoneNumber, 
              "created_by"=> $created_by,
              "first_name" => $first_name,
              "last_name" => $last_name,  
              "email" => $email);

		$json_data = json_encode($data);   
 
    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "https://api.toky.co/v1/contacts/");
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch,CURLOPT_POSTFIELDS, $json_data);
    
    $curl_response = curl_exec($ch); // Send request
  	curl_close($ch); // close cURL resource
    
		$return json_decode($curl_response,true);
}
	$result= createContact('+18443326433','[[TOKY_AGENT_EMAIL]]','Jhon','Doe','[email protected]');
  print "Contact creation result: "; var_export($result);

?>