Perform a Number Deactivation Check

var TeleSignSDK = require('telesignenterprisesdk');


console.log("## phoneid.numberDeactivation ##");

const customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; // Todo: find in teleportal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; // Todo: find in teleportal.telesign.com
const phoneNumber = "Your test phone number with no special characters or spaces.";
const ucid = "ATCK";

const client = new TeleSignSDK(customerId, apiKey);

function phoneidCallback(error, responseBody) {
    if (error === null) {

        if (responseBody.hasOwnProperty('number_deactivation') || responseBody['status'][]) {
            console.log(`PhoneID response for phone number: ${phoneNumber}` +
                ` => phone number: ${responseBody['number_deactivation']['number']}` +
                `, last deactivated: ${responseBody['number_deactivation']['last_deactivated']}`);
        } else {
            console.log(`Phone number ${phoneNumber} has not been deactivated.`);
            console.log(responseBody);
        }

    } else {
        console.error("Unable to send phoneID numberDeactivation. " + error);
    }
}

client.phoneid.numberDeactivation(phoneidCallback, phoneNumber, ucid);

This tutorial explains how to check whether a phone number was deactivated. You can use the check to decide whether to send someone an SMS or Voice message. If someone’s number is not active, you can save the cost of attempting to send a message.

This tutorial has the following sections:

Requirements

For this tutorial, the following is required:

  • customer ID - obtain from your account by logging in to teleportal.telesign.com (referred to as customer_id/customerId in this document)
  • API key - obtain from your account by logging in to teleportal.telesign.com (referred to as api_key/apiKey in this document)
  • SDK - Access to TeleSign’s GitHub repository for your selected language (you must request access from your Technical Account Manager):
  • Language Version
    • Node.js - 6+
    • Java - 7+
    • Python - 2.7+
    • Ruby - 2+
    • PHP - 5.6+
    • C# - 4.5+

Install the SDK

  1. Obtain your customer ID and API key.
  2. Log in to GitHub and navigate to the SDK in the language of your choice:
  3. Download or clone the repository. If you download it, extract the repository from the .ZIP file.
  4. To install the SDK for use, do the following:

Check if a Phone Number is Deactivated

This section explains how to check a phone number to see if it has been recently deactivated. The sample code provided earlier is broken out into pieces and explained below.

  1. Begin by adding statements for including the appropriate part of the TeleSign SDK and any additional language specific functions you may need.
var TeleSignSDK = require('telesignenterprisesdk');
  1. Insert values for each of the items from customer_id/customerId through to phone_number/phoneNumber.
    • customer_id / customerId - Your TeleSign assigned customer ID, available in your account information in the portal.
    • api_key / apiKey - Your TeleSign assigned API key, available in your account information in the portal.
    • phone_number / phoneNumber - The phone number you want to use for the example. When you provide the number, it should be a string with no spaces or special characters. Include the complete number. For example, if you are doing a phone number for America, you would include the country code and the area code with the number. For example 16505551212.
    • ucid - A string that specifies one of the use case codes. Use case codes provide information about what kind of transaction you are performing.
console.log("## phoneid.numberDeactivation ##");

const customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; // Todo: find in teleportal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; // Todo: find in teleportal.telesign.com
const phoneNumber = "Your test phone number with no special characters or spaces.";
const ucid = "ATCK";
  1. Instantiate a PhoneIdClient object and pass it your customer ID and API key. For node.js, it is just client.
const client = new TeleSignSDK(customerId, apiKey);
  1. Perform a number deactivation check, and store the results in the variable response/telesignResponse. For node.js, you use this step to create a function to handle the callback after you send a request for a number deactivation check.
function phoneidCallback(error, responseBody) {
    if (error === null) {

        if (responseBody.hasOwnProperty('number_deactivation') || responseBody['status'][]) {
            console.log(`PhoneID response for phone number: ${phoneNumber}` +
                ` => phone number: ${responseBody['number_deactivation']['number']}` +
                `, last deactivated: ${responseBody['number_deactivation']['last_deactivated']}`);
        } else {
            console.log(`Phone number ${phoneNumber} has not been deactivated.`);
            console.log(responseBody);
        }

    } else {
        console.error("Unable to send phoneID numberDeactivation. " + error);
    }
}
  1. The results stored in the response/telesignResponse variable are provided to you in this step. For node.js, this is where you finally send the request. You pass in the phoneidCallback function you created to handle the response.
client.phoneid.numberDeactivation(phoneidCallback, phoneNumber, ucid);
  1. You should receive a response containing details about whether your phone number is active or not. You can use these results to make decisions about what to do with the phone number. For example, if someone is trying to sign up for an account with an inactive number, you might require them to sign up using a different number. Or, if you needed to send the provided number a code via text or voice message, you might opt not to send the message since it will not reach a deactivated number.

Code it Without the SDK

TeleSign’s SDKs make implementation a lot easier because authentication is handled for you. If you want to write all your own code, you will need to handle authentication yourself. You need the following documents: