The Charge API uses an expand
parameter to include related objects in responses, reducing the need for multiple API calls and improving performance.
How It Works
By default, API responses include only the main object with IDs for related resources. Use the expand
parameter to include full objects instead of just IDs.
Check the endpoint documentation for available expand options.
Without Expansion
{
"id": "cs_123",
"object": "charging_session",
"charging_station": "cs_456",
"driver": "drv_789",
"vehicle": "veh_101"
}
With Expansion
curl https://api.chargeapi.co/v1/charging_sessions/cs_123 \
-H "Authorization: Bearer ch_sk_test_..." \
-d "expand[]=charging_station&expand[]=driver&expand[]=vehicle"
{
"id": "cs_123",
"object": "charging_session",
"charging_station": {
"id": "cs_456",
"object": "charging_station",
"name": "Downtown Station",
"location": { "latitude": 40.7128, "longitude": -74.0060 }
},
"driver": {
"id": "drv_789",
"object": "driver",
"name": "John Doe",
"email": "john@example.com"
},
"vehicle": {
"id": "veh_101",
"object": "vehicle",
"vin": "1HGBH41JXMN109186",
"battery_capacity": 75000
}
}
Performance Tip
Use expansion strategically. For frequently accessed data, consider caching expanded responses to reduce API calls.