POST
/
accounts
/
{account_id}
/
phone_numbers
JavaScript
import Surge from '@surgeapi/node';

const client = new Surge({
  apiKey: 'My API Key',
});

const phoneNumber = await client.phoneNumbers.purchase('acct_01j9a43avnfqzbjfch6pygv1td');

console.log(phoneNumber.id);
{
  "id": "pn_01jsjwe4d9fx3tpymgtg958d9w",
  "number": "+18015551234",
  "type": "local"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

account_id
string
required

The account for which the phone number should be created.

Example:

"acct_01j9a43avnfqzbjfch6pygv1td"

Body

application/json

Parameters for purchasing a new phone number. The system will automatically infer the type in certain cases:

  • If only area_code is provided, type is inferred from the area code
  • If only latitude/longitude are provided, type is inferred as 'local'
  • Otherwise, type must be explicitly specified
area_code
string

The desired area code for this phone number. If provided without type, the type will be inferred.

Example:

"801"

latitude
number

Latitude to search for nearby phone numbers. Must be used with longitude. If provided without type, type will be inferred as 'local'.

Required range: -90 <= x <= 90
Example:

40.7128

longitude
number

Longitude to search for nearby phone numbers. Must be used with latitude. If provided without type, type will be inferred as 'local'.

Required range: -180 <= x <= 180
Example:

-74.006

type
enum<string>

Whether the phone number is local or toll-free. Can be omitted if area_code or latitude/longitude are provided.

Available options:
local,
toll_free
Example:

"local"

Response

Purchased phone number

A phone number that can be used to send and receive messages and calls

id
string
required

Unique identifier for the phone number

number
string<phone-number>
required

The phone number in E.164 format

Example:

"+18015551234"

type
enum<string>
required

Whether the phone number is local, toll-free, or short code

Available options:
local,
toll_free