PHP SDK Documentation
The PHP SDK provides a basic interface to the DataSoap API, allowing developers to
build bespoke solutions quickly using our data cleansing / validation services.
Installing
You can download the latest and greatest version of the Data Soap SDK for PHP below.
Using the SDK
Place the 'DataSoap.php' file into your projects directory and import it into your code using 'require "DataSoap.php"'
To start making requests to the API you need to define a variable and assign it to a new instance of 'DataSoap.Client()', you can then give it your api token with '$client->WithAuthToken("your_private_token")'
<?php require "DataSoap.php"; $client = new DataSoap(); $client->WithAuthToken("your_private_token"); ?>
Note: There is a third parameter which can be used to disable certificate validation i.e. 'DataSoap(username,password,false)', It is not recommended to use this in production!
The client includes methods for each service it supports. In the case of an error the client will return an ErrorCode which directly relates to our error code list. It is important that error codes are correctly handled as some services such as HLR will throw exception in certain events such as ‘Dead number’
Examples
$client = new DataSoap(); $client->WithAuthToken("your_private_token"); $number = "your_number"; # Send request $res = $client->TpsLookup($number); if( isset($res->{"ErrorCode"}) ){ # Handle api errors print("Error: " . $res->{"ErrorCode"}); }else{ # Result print("Number: " . $res->{"MSISDN"} . "\r\n"); print("On TPS: " . ($res->{"TPS"}?"Yes":"No") . "\r\n"); print("On CTPS: " . ($res->{"CTPS"}?"Yes":"No") . "\r\n"); print("On DNC: " . ($res->{"DNC"}?"Yes":"No") . "\r\n"); }
$client = new DataSoap(); $client->WithAuthToken("your_private_token"); $number = "your_mobile_number"; # Send request $res = $client->HlrLookup($number); if( isset($res->{"ErrorCode"}) ){ # Handle api errors print("Error: " . $res->{"ErrorCode"}); }else{ # Result print("Number: " . $res->{"MSISDN"} . "\r\n"); print("Is On: " . ($res->{"On"}?"Yes":"No") . "\r\n"); print("Network: " . $res->{"NetworkName"} . "\r\n"); print("MNCMCC: " . $res->{"MNC"} . $res->{"MCC"} . "\r\n"); }
$client = new DataSoap(); $client->WithAuthToken("your_private_token"); $number = "your_landline_number"; # Send request $res = $client->LandlineLookup($number); if( isset($res->{"ErrorCode"}) ){ # Handle api errors echo "Error: " . $res->{"ErrorCode"}; }else{ # Result print("Number: " . $res->{"Number"} . "\r\n"); print("Is Active: " . ($res->{"IsActive"}?"Yes":"No") . "\r\n"); }
$client = new DataSoap(); $client->WithAuthToken("your_private_token"); $email = "your_email"; # Send request $res = $client->EmailLookup($email); if( isset($res->{"ErrorCode"}) ){ # Handle api errors print("Error: " . $res->{"ErrorCode"}); }else{ # Result print("Number: " . $res->{"Email"} . "\r\n"); print("Is High Quality: " . ($res->{"IsHighQuality"}?"Yes":"No") . "\r\n"); print("Is Free: " . ($res->{"IsFree"}?"Yes":"No") . "\r\n"); print("IsDisposable: " . ($res->{"IsDisposable"}?"Yes":"No") . "\r\n"); print("Is Role: " . ($res->{"IsRole"}?"Yes":"No") . "\r\n"); }
$client = new DataSoap(); $client->WithAuthToken("your_private_token"); $number = "your_number"; # Send request $res = $client->UnsubscribeLookup($number); if( isset($res->{"ErrorCode"}) ){ # Handle api errors echo "Error: " . $res->{"ErrorCode"}; }else{ # Result print("Number: " . $res->{"MSISDN"} . "\r\n"); print("On Company List: " . ($res->{"OnCompany"}?"Yes (".$res->{"OnCompanyDateAdded"} ."":"No") . "\r\n"); if( isset($res->{"OnGlobal"}) ){ print("On Global List: " . ($res->{"OnGlobal"}?"Yes (".$res->{"OnGlobalDateAdded"} ."":"No") . "\r\n"); } }