API Documentation
Getting Started
The Global City Explorer API provides access to our comprehensive database of city information, including population data, geographic coordinates, climate information, and more.
Base URL
https://api.globalcityexplorer.com/v1
API Versions
- v1: Current stable version
- beta: Experimental features
Authentication
All API requests require authentication using an API key. You can obtain an API key by signing up for an account on our platform.
How to Authenticate
Include your API key in the header of each request:
Authorization: Bearer YOUR_API_KEY
API Key Management
- Generate API keys from your account dashboard
- Revoke API keys at any time
- Set permissions for each API key
- Monitor API key usage and analytics
API Endpoints
The Global City Explorer API provides the following endpoints:
Cities
GET /cities
List all cities with optional filters
GET /cities?country=US&population_min=100000
GET /cities/{id}
Get details for a specific city
GET /cities/12345
GET /cities/search
Search for cities by name
GET /cities/search?q=New York
Countries
GET /countries
List all countries
GET /countries
GET /countries/{code}
Get details for a specific country
GET /countries/US
Statistics
GET /statistics/cities
Get statistical data for cities
GET /statistics/cities?metric=population&year=2025
Nearby
GET /nearby
Find cities near a specific location
GET /nearby?lat=40.7128&lon=-74.0060&radius=50
Rate Limits
To ensure fair usage and system stability, the Global City Explorer API has rate limits in place.
Rate Limit Tiers
| Plan | Requests per Minute | Requests per Day |
|---|---|---|
| Free | 60 | 10,000 |
| Basic | 300 | 100,000 |
| Pro | 1,000 | 1,000,000 |
| Enterprise | Custom | Custom |
Rate Limit Headers
API responses include the following headers to help you monitor your rate limit usage:
X-RateLimit-Limit:The maximum number of requests allowed per minuteX-RateLimit-Remaining:The number of requests remaining in the current windowX-RateLimit-Reset:The timestamp when the rate limit window will reset
Response Formats
The Global City Explorer API returns responses in JSON format by default.
Success Response Example
{
"status": "success",
"data": {
"id": 12345,
"name": "New York",
"country": "United States",
"country_code": "US",
"latitude": 40.7128,
"longitude": -74.0060,
"population": 8336817,
"area": 783.84,
"timezone": "America/New_York",
"currency": "USD",
"language": "English"
},
"metadata": {
"timestamp": 1717248000,
"request_id": "abc123"
}
}
Error Response Example
{
"status": "error",
"message": "City not found",
"code": 404,
"metadata": {
"timestamp": 1717248000,
"request_id": "def456"
}
}
Error Codes
- 400 Bad Request: Invalid request parameters
- 401 Unauthorized: Invalid or missing API key
- 404 Not Found: Requested resource not found
- 429 Too Many Requests: Rate limit exceeded
- 500 Internal Server Error: Server error
Code Examples
Here are some examples of how to use the Global City Explorer API in different programming languages:
JavaScript (Fetch API)
const apiKey = 'YOUR_API_KEY';
const cityId = 12345;
fetch(`https://api.globalcityexplorer.com/v1/cities/${cityId}`, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
console.log('City data:', data);
})
.catch(error => {
console.error('Error:', error);
});
Python (Requests)
import requests
api_key = 'YOUR_API_KEY'
city_id = 12345
url = f'https://api.globalcityexplorer.com/v1/cities/{city_id}'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
data = response.json()
print('City data:', data)
PHP (cURL)
Frequently Asked Questions
How do I get an API key?
You can obtain an API key by signing up for an account on our platform and navigating to the API section of your dashboard.
Is there a free tier for the API?
Yes, we offer a free tier with limited requests per minute and per day. You can upgrade to a paid plan for higher rate limits and additional features.
What data is available through the API?
The API provides access to city information including population, geographic coordinates, area, timezone, currency, language, and more. We also provide statistical data and nearby city search functionality.
How often is the API data updated?
Our database is updated regularly with the latest available data from official sources. Major updates occur quarterly, with minor updates happening monthly.
Can I use the API for commercial purposes?
Yes, you can use the API for commercial purposes with the appropriate plan. Please refer to our terms of service for more information.