Phone ID - Tutorial: Use Contact Match with Telesign PHP SDK
NOTE:
To add Contact Match to your account, contact a Telesign expert. This feature is available for full-service accounts only.
This tutorial describes how to use the Phone ID Contact Match identity attribute with the Telesign PHP SDK, guiding you step-by-step through the creation of an integration that uses the Phone ID Contact Match. Skip to the end of this page to see the full sample code.
Before you begin
Make sure you have the following before you start:
- Authentication credentials: Your Customer ID and API Key. If you need help finding these items, go to the support article How do I find my Customer ID and API Key.
- Identity attribute enabled - Make sure the Contact Match identity attribute is enabled by Telesign. If it is not yet enabled, contact a Telesign expert.
- Phone number - The phone number you want to get information about.
- Composer: This package manager isn't required to use the SDK, but it is required for this tutorial.
NOTE:
This tutorial uses the following:
- MacOS
- PHP v8.4.2
- Composer v2.8.4
Please modify accordingly if your developer environment differs from these details.
Set up your project
-
Follow the Telesign Full-service PHP SDK install instructions here on GitHub incorporating these details:
- Use
phoneidtest
as the project directory. - Use
project
as the Package Type. - Use
no
for defining both yourrequire
andrequire-dev
dependencies interactively. - Use the default directory
src/
for PSR-4 autoload mapping.
You should end up in the top-level directory for your project in the Terminal.
- Use
-
Create a new file in the "src" directory called
phone_id_contact_match.php
and open it in your editor.touch src/phone_id_contact_match.php
Make a Contact Match request
-
Follow the steps below or copy the sample code into the file and update accordingly.
-
Add a script opening tag.
<?php
-
Add the imports after the script opening tag. The
telesign\enterprise\sdk\phoneid\PhoneIdClient
import pulls selected functionality from the Telesign full-service SDK.require __DIR__ . "/../vendor/autoload.php"; use telesign\enterprise\sdk\phoneid\PhoneIdClient;
NOTE:
The
require
line may need to be modified depending on the location of "autoload.php" in your file system. By default, Composer generates this file in a "vendor" directory at the top-level of your project, as indicated by the path shown in the example above. -
Define variables to store your authentication credentials.
$customer_id = getenv('CUSTOMER_ID') ?? 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890'; $api_key = getenv('API_KEY') ?? 'ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==';
-
Define a variable to hold the phone number you want to get information for. Use the complete number, including the country code. This should be a string with no spaces or special characters. For example:
16505551212
.$phone_number = getenv('PHONE_NUMBER') ?? '11234567890';
NOTE:
In your production integration, pull the phone number from your recipient database instead of hardcoding it.
-
Define variables to hold the first name and last name that you want to match.
$first_name = 'Put the first name you are matching for here.'; $last_name = 'Put the last name you are matching for here.';
-
Instantiate a
PhoneIdClient
object containing your Customer ID and API Key.$client = new PhoneIdClient($customer_id, $api_key);
-
Make the request and capture the response. Store the object, and pass it your phone number then pass the identity attribute,
contact_match
, that you want to use.$response = $client->phoneid($phone_number, [ "addons" => [ "contact_match" => [ "first_name" => $first_name, "last_name" => $last_name] ] ] );
-
Display the response body in the console for debugging purposes. In your production code, you would likely remove this.
print_r($response->json);
-
Add the closing tag for the script.
?>
Test your integration
-
Switch from your editor to the terminal and run:
php src/phone_id_contact_match.php
Sample code
<?php
require __DIR__ . "/../vendor/autoload.php";
use telesign\enterprise\sdk\phoneid\PhoneIdClient;
$customer_id = getenv('CUSTOMER_ID') ?? 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890';
$api_key = getenv('API_KEY') ?? 'ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==';
$phone_number = getenv('PHONE_NUMBER') ?? '11234567890';
$first_name = 'Put the first name you are matching for here.';
$last_name = 'Put the last name you are matching for here.';
$client = new PhoneIdClient($customer_id, $api_key);
$response = $client->phoneid($phone_number,
[
"addons" => [
"contact_match" => [
"first_name" => $first_name,
"last_name" => $last_name]
]
]
);
print_r($response->json);
?>
Updated about 14 hours ago