Purchase Numbers
Purchase phone numbers for your account. You can buy directly from a group or purchase a previously reserved number.
Endpoint
POST https://api.p.2chat.io/open/numbers/purchase
Authentication
Include your API key in the X-User-API-Key header. Learn more about authentication.
Parameters
These parameters should be sent as JSON payload in the request body.
| Field | Type | Required | Description |
|---|---|---|---|
group_id | string | Yes | The group ID from the Search Number Groups endpoint |
number | string | No | A specific number to purchase (from the Available Numbers endpoint or a reservation). If omitted, a random number from the group is assigned. |
Invocation
- cURL
- Python
- JavaScript
- PHP
curl --location --request POST 'https://api.p.2chat.io/open/numbers/purchase' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here' \
--data '{
"group_id": "abc-123",
"number": "+12135551234"
}'
import requests
url = "https://api.p.2chat.io/open/numbers/purchase"
headers = {
"Content-Type": "application/json",
"X-User-API-Key": "your_api_key_here"
}
payload = {
"group_id": "abc-123",
"number": "+12135551234"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const axios = require('axios');
const response = await axios.post('https://api.p.2chat.io/open/numbers/purchase', {
group_id: 'abc-123',
number: '+12135551234'
}, {
headers: {
'Content-Type': 'application/json',
'X-User-API-Key': 'your_api_key_here'
}
});
console.log(response.data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.p.2chat.io/open/numbers/purchase',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'group_id' => 'abc-123',
'number' => '+12135551234'
]),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'X-User-API-Key: your_api_key_here'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Response
Success (HTTP 201 Created)
{
"success": true
// Purchase result details
}
Error
{
"success": false,
"error": true,
"error_message": "Description of what went wrong"
}
Typical Purchase Flow
The complete flow for purchasing a phone number is:
- Find a location —
GET /open/numbers/regionsandGET /open/numbers/citiesto narrow down by region and city - Search groups —
GET /open/numbers/groupsto find number groups by country, region, city, or type - Check requirements —
GET /open/numbers/requirementsto verify if regulatory documents are needed - Browse numbers (optional) —
GET /open/numbers/availableto pick a specific number from a group - Purchase —
POST /open/numbers/purchasewith agroup_idand optionally a specificnumber
tip
If you need to hold a number before committing (e.g., to show it to a user before charging), you can reserve it first and then purchase before it expires.