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

const client = new Surge({
  apiKey: process.env['SURGE_API_KEY'], // This is the default and can be omitted
});

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

console.log(phoneNumber.id);
import os
from surge import Surge

client = Surge(
api_key=os.environ.get("SURGE_API_KEY"), # This is the default and can be omitted
)
phone_number = client.phone_numbers.purchase(
account_id="acct_01j9a43avnfqzbjfch6pygv1td",
)
print(phone_number.id)
package main

import (
"context"
"fmt"

"github.com/stainless-sdks/surge-go"
"github.com/stainless-sdks/surge-go/option"
)

func main() {
client := surge.NewClient(
option.WithAPIKey("My API Key"),
)
phoneNumber, err := client.PhoneNumbers.Purchase(
context.TODO(),
"acct_01j9a43avnfqzbjfch6pygv1td",
surge.PhoneNumberPurchaseParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", phoneNumber.ID)
}
require "surge_api"

surge = SurgeAPI::Client.new(api_key: "My API Key")

phone_number = surge.phone_numbers.purchase("acct_01j9a43avnfqzbjfch6pygv1td")

puts(phone_number)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Surge\Client;
use Surge\Core\Exceptions\APIException;

$client = new Client(apiKey: getenv('SURGE_API_KEY') ?: 'My API Key');

try {
$phoneNumber = $client->phoneNumbers->purchase(
'acct_01j9a43avnfqzbjfch6pygv1td',
areaCode: '801',
latitude: 40.7128,
longitude: -74.006,
name: 'Support Line',
type: 'local',
);

var_dump($phoneNumber);
} catch (APIException $e) {
echo $e->getMessage();
}
curl --request POST \
--url https://api.surge.app/accounts/{account_id}/phone_numbers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"area_code": "801",
"latitude": 40.7128,
"longitude": -74.006,
"name": "Support Line",
"type": "local"
}
'
HttpResponse<String> response = Unirest.post("https://api.surge.app/accounts/{account_id}/phone_numbers")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"area_code\": \"801\",\n \"latitude\": 40.7128,\n \"longitude\": -74.006,\n \"name\": \"Support Line\",\n \"type\": \"local\"\n}")
.asString();
{
  "campaign_id": "cpn_01jjnn7s0zfx5tdcsxjfy93et2",
  "id": "pn_01jsjwe4d9fx3tpymgtg958d9w",
  "name": "(801) 555-1234",
  "number": "+18015551234",
  "type": "local"
}
{
"error": {
"message": "The requested resource could not be found.",
"type": "not_found"
}
}

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.

Pattern: ^\d{3}$
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

name
string

A human-readable name for the phone number. If not provided, defaults to the formatted phone number.

Example:

"Support Line"

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

campaign_id
string | null
required

The unique identifier of the campaign this phone number is attached to, if any

id
string
required

Unique identifier for the phone number

name
string | null
required

A human-readable name for the phone number

number
string<phone-number>
required

The phone number in E.164 format

Pattern: ^\+[1-9]\d{6,14}$
Example:

"+18015551234"

type
enum<string>
required

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

Available options:
local,
short_code,
toll_free