API Client Code Examples

Do you need to call Veriphone API from your PHP, Java, Javascript or Python code? We developed and tested these code examples so you you dont have to do it yourself. All you have to do is copy one of the scripts in this page, plug your API key and your phone number variable, then use the verification results as you wish like shown in the code. Happy coding!

Javascript


var phone = 'Phone number';
var key = 'Your API key';
var default_country = 'Country code';
$.ajax({
    url: 'https://api.veriphone.io/v2/verify',
    method: 'POST',
    data:{phone: phone, key: key, default_country: default_country},   
    dataType: 'json',
    success: function(data) {
        console.log(data.phone_valid);   
        console.log(data.country);
        console.log(data.international_number);  
        console.log(data.carrier);         
    }
});

PHP (cURL)


$phone = 'Phone number';
$key = 'Your API key';
$default_country = 'Country code';
$ch = curl_init('https://api.veriphone.io/v2/verify?phone='.$phone.'&key='.$key.'&default_country='.$default_country);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
$validationResult = json_decode($json, true);
echo $validationResult['phone_valid'];
echo $validationResult['country'];
echo $validationResult['international_number'];
echo $validationResult['carrier'];

Java (OkHttp)


import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONObject;
public void veri(String phone, String key, String default_country) {
    //phone is the phone number wich you want to check
    //key is your API key
    //default_country is the country code
    String url = "https://api.veriphone.io/v2/verify?phone="+phone+"&key="+key+"&default_country="+default_contry;
    OkHttpClient client = new OkHttpClient().newBuilder().build();
    Request request = new Request.Builder().url(url).method("GET", null).build();
    Response response = client.newCall(request).execute();
    String resultat = response.body().string();
    JSONObject myObject = new JSONObject(resultat);
    System.out.println(myObject.getBoolean("phone_valid"));
    System.out.println(myObject.getString("country"));
    System.out.println(myObject.getString("international_number"));
    System.out.println(myObject.getString("carrier"));
}

Python (HttpClient)


import http.client
import mimetypes
import json
    conn = http.client.HTTPSConnection("api.veriphone.io")
    phone = 'Phone number'
    key = 'Your API KEY'
    default_country = 'Country code'
    url = '/v2/verify?phone='+phone+'&key='+key+'&default_country='+default_country
    conn.request("GET", url)
    res = conn.getresponse()
    datajs = res.read()
    data = json.loads(datajs.decode("utf-8"))
    print(data['phone_valid'])
    print(data['country'])
    print(data['international_number'])
    print(data['carrier'])