Phone ID - Tutorial: Use identity attributes

This tutorial walks you step-by-step through how to write code that makes a request to Phone ID that includes the Contact identity attribute.

An identity attribute provides additional information about a phone number with one call to Phone ID. This is in addition to the standard response fields for Phone ID. You get back status information for each identity attribute enabled and requested.

Before you begin

Make sure you have the following ready:

Steps

  1. Copy the sample code below into a send_pid_contact_request.py file on your local machine.
  2. Install the requests module and HTTPBasicAuth from requests.auth.

Python

from requests.auth import HTTPBasicAuth
import requests
  1. Insert values for the following variables:

    • complete_phone_number - The phone number you want to get information about.
    • CUSTOMER_ID - Your Telesign Customer ID.
    • API_KEY - Your Telesign API Key.
  2. Run the program. If the call is successful, you should get a response payload that looks like this:

{
  "contact": {
    "address1": "2432 CHIMNEY POINT LN",
    "address2": "",
    "address3": "",
    "address4": "",
    "city": "LEXINGTON",
    "country": "",
    "first_name": "MYLA",
    "last_name": "JONES",
    "state_province": "KY",
    "status": {
      "code": 2800,
      "description": "Request successfully completed"
    },
    "zip_postal_code": "40509",
    "email_address": "[email protected]"
  }
}

Sample code

from requests.auth import HTTPBasicAuth
import requests

url = 'https://rest-ww.telesign.com/v1/phoneid/<complete_phone_number>'
headers = {'Accept' : 'application/json', 'Content-Type' : 'application/json'}
r = requests.post(url, auth=HTTPBasicAuth('CUSTOMER_ID', 'API_KEY'), json={'addons':{'contact':{}}}, headers=headers)

print(r.content)
require 'net/http'
require 'uri'
require 'json' 
require 'rest-client'

response = RestClient::Request.new({
      method: :post,
      url: 'https://rest-ww.telesign.com/v1/phoneid/<complete_phone_number>',
      user: 'Customer ID',
      password: 'API Key',
      payload: { 'addons': {'contact':{}} },
      headers: { :accept => :json, content_type: :json }
    }).execute do |response, request, result|
      case response.code
      when 400
        [ :error, JSON.parse(response.to_str) ]
      when 200
        [ :success, JSON.parse(response.to_str) ]
      else
        fail "Invalid response #{response.to_str} received."
      end
    end

Did this page help you?