Telephony API

Buy phone numbers via an API

The Sonetel API allows you to instantly buy phone numbers in any country and city of choice.

Phone numbers purchased via the API receive a $1 discount on the monthly renewal fee. This means that phone numbers cost from $0.79 per month.

 

How to buy a phone number via the API

This is how it works.

  1. Supported countries
    Get a list of the countries where phone numbers can be purchased.
  2. See supported number types and number availability
    Get a list of all area codes and number types in a specific country (city area codes, toll free, national, mobile numbers etc.) and the quantity of phone numbers that are available per city and prefix.
  3. See available numbers
    Get a list of phone numbers available for ordering, of the specified type in the selected country.
  4. Buy a number
    Buy a number and have it added to your account.

In the next step you can configure the call forwarding of your new phone number.

If your account is verified, and the phone number selected isn’t subject to specific activation restrictions – the number will become activated instantly.

 

Buying a phone number with Python

A sample script for buying phone number with Python can be found here. The script can be used after finding an available number for purchasing.

The script starts by importing the necessary modules, and then defines the phone number to be purchased and the base URL of the Sonetel API.

Next, it sets the access token for the API and decodes it to get the account ID of the user. It then constructs the request headers and sends an HTTP POST request to the /account/{account_id}/phonenumbersubscription endpoint of the Sonetel API, passing the phone number and the access token in the request body and headers, respectively.

If the request is successful, the response is printed to the console. Otherwise, an error is raised.

To use the script, you will need to enter your own access token and the phone number you want to purchase. You can obtain the access token by following the instructions in the documentation at https://docs.sonetel.com.

 

Buying a phone number with NodeJS

A sample script for buying phone number with NodeJS can be found here. The script can be used after finding an available number for purchasing.

The NodeJS module exports a function called buyPhoneNumber. This function can be used to purchase a phone number using the Sonetel API. The function accepts two arguments:

  1. accessToken: The access token to authorize the request with Sonetel’s API.
  2. numToPurchase: The phone number to purchase, in the E164 format (without the leading “+”).

The function starts by checking that the accessToken and numToPurchase arguments are provided. If either is missing, an error is thrown. The access token is then decoded and the account ID is extracted.

Next, the function constructs an HTTP POST request to the /account/{account_id}/phonenumbersubscription endpoint of the Sonetel API, passing the phone number and access token in the request body and headers, respectively. The response is handled asynchronously and, if it is successful, the response data is logged to the console. Otherwise, an error is thrown.

To use the function, you will need to import it into your script and call it with your own access token and the phone number you want to purchase. You can obtain the access token by following the instructions here.

 

English