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)require "surge_api"
surge = SurgeAPI::Client.new(api_key: "My API Key")
phone_number = surge.phone_numbers.purchase("acct_01j9a43avnfqzbjfch6pygv1td")
puts(phone_number)curl --request POST \
--url https://api.surge.app/accounts/{account_id}/phone_numbers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"description": "Purchase any available local number",
"summary": "Random local number",
"value": {
"type": "local"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.surge.app/accounts/{account_id}/phone_numbers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'description' => 'Purchase any available local number',
'summary' => 'Random local number',
'value' => [
'type' => 'local'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.surge.app/accounts/{account_id}/phone_numbers"
payload := strings.NewReader("{\n \"description\": \"Purchase any available local number\",\n \"summary\": \"Random local number\",\n \"value\": {\n \"type\": \"local\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}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 \"description\": \"Purchase any available local number\",\n \"summary\": \"Random local number\",\n \"value\": {\n \"type\": \"local\"\n }\n}")
.asString();{
"campaign": {
"attachment_status": "attached",
"id": "cpn_01jjnn7s0zfx5tdcsxjfy93et2"
},
"campaign_id": "cpn_01jjnn7s0zfx5tdcsxjfy93et2",
"id": "pn_01jsjwe4d9fx3tpymgtg958d9w",
"metadata": {
"location": "Downtown store"
},
"name": "(801) 555-1234",
"number": "+18015551234",
"type": "local"
}{
"error": {
"message": "The requested resource could not be found.",
"type": "not_found"
}
}Phone numbers
Purchase phone number
Purchase a local or toll-free phone number and assign it to an account.
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)require "surge_api"
surge = SurgeAPI::Client.new(api_key: "My API Key")
phone_number = surge.phone_numbers.purchase("acct_01j9a43avnfqzbjfch6pygv1td")
puts(phone_number)curl --request POST \
--url https://api.surge.app/accounts/{account_id}/phone_numbers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"description": "Purchase any available local number",
"summary": "Random local number",
"value": {
"type": "local"
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.surge.app/accounts/{account_id}/phone_numbers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'description' => 'Purchase any available local number',
'summary' => 'Random local number',
'value' => [
'type' => 'local'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.surge.app/accounts/{account_id}/phone_numbers"
payload := strings.NewReader("{\n \"description\": \"Purchase any available local number\",\n \"summary\": \"Random local number\",\n \"value\": {\n \"type\": \"local\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}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 \"description\": \"Purchase any available local number\",\n \"summary\": \"Random local number\",\n \"value\": {\n \"type\": \"local\"\n }\n}")
.asString();{
"campaign": {
"attachment_status": "attached",
"id": "cpn_01jjnn7s0zfx5tdcsxjfy93et2"
},
"campaign_id": "cpn_01jjnn7s0zfx5tdcsxjfy93et2",
"id": "pn_01jsjwe4d9fx3tpymgtg958d9w",
"metadata": {
"location": "Downtown store"
},
"name": "(801) 555-1234",
"number": "+18015551234",
"type": "local"
}{
"error": {
"message": "The requested resource could not be found.",
"type": "not_found"
}
}Authorizations
Path Parameters
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
If phone_number is provided, all other search parameters are ignored.
Response
Purchased phone number
A phone number that can be used to send and receive messages and calls