Country From Phone Number API

This API retrieves the country name and country code from a given phone number.

URL: https://api.apipip.com/v1/phone-country/


Parameters

Name Description
phone_number (Required) The phone number you want to look up.

Headers

Name Description
X-Key (No required)

How to use Country From Phone Number API

                
import requests

# Set the API endpoint URL
url = 'https://api.apipip.com/v1/phone-country/'

# Set the phone number you want to look up
payload = {
    "phone_number": "+14155552671"
}

# Send a POST request to the API
response = requests.post(url, json=payload)

print(response.text)
                
                    
                
const url = 'https://api.apipip.com/v1/phone-country/';

// Set the phone number you want to look up
const payload = {
  phone_number: "+14155552671"
};

// Send a POST request to the API
fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(payload)
})
  .then(response => response.text())
  .then(data => {
    // Print the response
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
                
                    
                
import Foundation

// Set the API endpoint URL
let url = URL(string: "https://api.apipip.com/v1/phone-country/")!

// Set the phone number you want to look up
let payload = ["phone_number": "+14155552671"]

// Create the request
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

// Send the request
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
    if let error = error {
        print("Error: \(error)")
        return
    }
    
    guard let data = data else {
        print("No data received")
        return
    }
    
    if let responseString = String(data: data, encoding: .utf8) {
        // Print the response
        print(responseString)
    } else {
        print("Invalid response format")
    }
}

task.resume()
                
                    

API Response

                            
{
  "country": "United States",
  "country_code": "US"
}
                            
                                

Note: The API works with all programming languages