Created
October 3, 2021 14:24
-
-
Save ochui/7c35914f7a85f346adb98aaec87c39d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_linetype( $phone_number ) { | |
// Your Signalwire project id | |
$project_id = ''; | |
// Your signalwire API Auth Token | |
$auth_token = ''; | |
// Your signalwire Space URL | |
$space_url = ''; | |
$ch = curl_init(); | |
curl_setopt( $ch, CURLOPT_URL, "https://$space_url/api/relay/rest/lookup/phone_number/$phone_number?include=carrier" ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |
curl_setopt( $ch, CURLOPT_USERPWD, "$project_id" . ':' . "$auth_token" ); | |
$get_response = curl_exec( $ch ); | |
if ( curl_errno( $ch ) ) { | |
echo 'Error:' . curl_error( $ch ); | |
} | |
$phone_number_carrier_data = json_decode( $get_response, true ); | |
$phone_number_carrier_data = $phone_number_carrier_data['carrier']; // now you have all info about the number | |
// you can get the number type like so | |
return $phone_number_carrier_data['linetype']; | |
} | |
// use function | |
$linetype = get_linetype( '+1xxxxxxxxxx'); // this function returns an array | |
echo $linetype; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment