Get Cities
Get the available cities for a given country. Optionally filter by region to narrow down results.
Endpoint
GET https://api.p.2chat.io/open/numbers/cities
Authentication
Include your API key in the X-User-API-Key header. Learn more about authentication.
Parameters
These are query-string parameters.
| Field | Type | Required | Description |
|---|---|---|---|
country | string | Yes | ISO country code (e.g. US, BR, DE) |
region | string | No | Region ID to filter cities (from the Get Regions endpoint) |
Invocation
- cURL
- Python
- JavaScript
- PHP
curl --location --request GET 'https://api.p.2chat.io/open/numbers/cities?country=US®ion=123' \
--header 'X-User-API-Key: your_api_key_here'
import requests
url = "https://api.p.2chat.io/open/numbers/cities"
headers = {
"X-User-API-Key": "your_api_key_here"
}
params = {
"country": "US",
"region": "123"
}
response = requests.get(url, headers=headers, params=params)
print(response.json())
const axios = require('axios');
const response = await axios.get('https://api.p.2chat.io/open/numbers/cities', {
params: { country: 'US', region: '123' },
headers: {
'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/cities?country=US®ion=123',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'X-User-API-Key: your_api_key_here'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Response
Success
{
"success": true,
"data": {
"cities": [
{
"id": 456,
"city_name": "Los Angeles",
"iso_country_code": "US"
}
]
}
}
| Field | Description |
|---|---|
cities[].id | City ID to use when searching for number groups |
cities[].city_name | Human-readable name of the city |
cities[].iso_country_code | ISO country code the city belongs to |
Error
{
"success": false,
"error": true,
"error_message": "Description of what went wrong"
}