Code Examples
Complete examples for the most common API operations.
Search for Chargers
- curl
- Python
- Node.js
- Go
curl -s "https://api.petitmonde.energy/api/v1/client/search?\
lat=52.52&lng=13.40&radius=25&connector_type=IEC_62196_T2_COMBO&limit=5" \
-H "X-API-Key: $API_KEY" | jq .
import requests
API_KEY = "your-api-key"
BASE_URL = "https://api.petitmonde.energy/api/v1/client"
response = requests.get(
f"{BASE_URL}/search",
headers={"X-API-Key": API_KEY},
params={
"lat": 52.52,
"lng": 13.40,
"radius": 25,
"connector_type": "IEC_62196_T2_COMBO",
"limit": 5,
},
)
response.raise_for_status()
data = response.json()
print(f"Found {data['total']} chargers")
for loc in data["results"]:
print(f" {loc['name']} — {loc['distance_km']:.1f} km — {loc['cpo_name']}")
const API_KEY = "your-api-key";
const BASE_URL = "https://api.petitmonde.energy/api/v1/client";
const params = new URLSearchParams({
lat: "52.52",
lng: "13.40",
radius: "25",
connector_type: "IEC_62196_T2_COMBO",
limit: "5",
});
const response = await fetch(`${BASE_URL}/search?${params}`, {
headers: { "X-API-Key": API_KEY },
});
const data = await response.json();
console.log(`Found ${data.total} chargers`);
data.results.forEach((loc) => {
console.log(` ${loc.name} — ${loc.distance_km.toFixed(1)} km — ${loc.cpo_name}`);
});
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
func main() {
apiKey := "your-api-key"
baseURL := "https://api.petitmonde.energy/api/v1/client"
params := url.Values{
"lat": {"52.52"},
"lng": {"13.40"},
"radius": {"25"},
"connector_type": {"IEC_62196_T2_COMBO"},
"limit": {"5"},
}
req, _ := http.NewRequest("GET", baseURL+"/search?"+params.Encode(), nil)
req.Header.Set("X-API-Key", apiKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var data struct {
Total int `json:"total"`
Results []struct {
Name string `json:"name"`
DistanceKm float64 `json:"distance_km"`
CpoName string `json:"cpo_name"`
} `json:"results"`
}
json.NewDecoder(resp.Body).Decode(&data)
fmt.Printf("Found %d chargers\n", data.Total)
for _, loc := range data.Results {
fmt.Printf(" %s — %.1f km — %s\n", loc.Name, loc.DistanceKm, loc.CpoName)
}
}
Create a Booking
- curl
- Python
- Node.js
- Go
curl -s -X POST https://api.petitmonde.energy/api/v1/client/bookings \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"location_id": "DE-ENB-E123456",
"evse_uid": "DE*ENB*E123456*1",
"connector_id": "1",
"reservation_start": "2026-02-10T14:00:00Z",
"reservation_end": "2026-02-10T16:00:00Z",
"external_id": "my-ref-001"
}' | jq .
response = requests.post(
f"{BASE_URL}/bookings",
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json",
},
json={
"location_id": "DE-ENB-E123456",
"evse_uid": "DE*ENB*E123456*1",
"connector_id": "1",
"reservation_start": "2026-02-10T14:00:00Z",
"reservation_end": "2026-02-10T16:00:00Z",
"external_id": "my-ref-001",
},
)
if response.status_code == 202:
booking = response.json()
print(f"Booking created: {booking['id']} — status: {booking['status']}")
elif response.status_code == 429:
wait = int(response.headers.get("Retry-After", 60))
print(f"Rate limited. Retry after {wait} seconds.")
else:
print(f"Error {response.status_code}: {response.json()['error']}")
const response = await fetch(`${BASE_URL}/bookings`, {
method: "POST",
headers: {
"X-API-Key": API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
location_id: "DE-ENB-E123456",
evse_uid: "DE*ENB*E123456*1",
connector_id: "1",
reservation_start: "2026-02-10T14:00:00Z",
reservation_end: "2026-02-10T16:00:00Z",
external_id: "my-ref-001",
}),
});
if (response.status === 202) {
const booking = await response.json();
console.log(`Booking created: ${booking.id} — status: ${booking.status}`);
} else if (response.status === 429) {
const wait = response.headers.get("Retry-After") || 60;
console.log(`Rate limited. Retry after ${wait} seconds.`);
} else {
const err = await response.json();
console.log(`Error ${response.status}: ${err.error}`);
}
body := map[string]interface{}{
"location_id": "DE-ENB-E123456",
"evse_uid": "DE*ENB*E123456*1",
"connector_id": "1",
"reservation_start": "2026-02-10T14:00:00Z",
"reservation_end": "2026-02-10T16:00:00Z",
"external_id": "my-ref-001",
}
jsonBody, _ := json.Marshal(body)
req, _ := http.NewRequest("POST", baseURL+"/bookings", bytes.NewReader(jsonBody))
req.Header.Set("X-API-Key", apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode == 202 {
var booking map[string]interface{}
json.NewDecoder(resp.Body).Decode(&booking)
fmt.Printf("Booking created: %s — status: %s\n", booking["id"], booking["status"])
} else if resp.StatusCode == 429 {
wait := resp.Header.Get("Retry-After")
fmt.Printf("Rate limited. Retry after %s seconds.\n", wait)
}
Check Booking Status
- curl
- Python
- Node.js
- Go
curl -s https://api.petitmonde.energy/api/v1/client/bookings/BOOKING_ID \
-H "X-API-Key: $API_KEY" | jq '{status, cpo_reservation_id, client_price}'
import time
booking_id = "your-booking-id"
# Poll until confirmed or terminal state
while True:
response = requests.get(
f"{BASE_URL}/bookings/{booking_id}",
headers={"X-API-Key": API_KEY},
)
booking = response.json()
status = booking["status"]
print(f"Status: {status}")
if status in ("CONFIRMED", "COMPLETED", "CANCELLED", "EXPIRED", "NO_SHOW"):
break
time.sleep(5) # Poll every 5 seconds
const bookingId = "your-booking-id";
const poll = async () => {
while (true) {
const response = await fetch(`${BASE_URL}/bookings/${bookingId}`, {
headers: { "X-API-Key": API_KEY },
});
const booking = await response.json();
console.log(`Status: ${booking.status}`);
if (["CONFIRMED", "COMPLETED", "CANCELLED", "EXPIRED", "NO_SHOW"].includes(booking.status)) {
return booking;
}
await new Promise((r) => setTimeout(r, 5000));
}
};
bookingID := "your-booking-id"
terminalStates := map[string]bool{
"CONFIRMED": true, "COMPLETED": true, "CANCELLED": true,
"EXPIRED": true, "NO_SHOW": true,
}
for {
req, _ := http.NewRequest("GET", baseURL+"/bookings/"+bookingID, nil)
req.Header.Set("X-API-Key", apiKey)
resp, _ := http.DefaultClient.Do(req)
var booking map[string]interface{}
json.NewDecoder(resp.Body).Decode(&booking)
resp.Body.Close()
status := booking["status"].(string)
fmt.Printf("Status: %s\n", status)
if terminalStates[status] {
break
}
time.Sleep(5 * time.Second)
}
Cancel a Booking
- curl
- Python
- Node.js
- Go
curl -s -X POST https://api.petitmonde.energy/api/v1/client/bookings/BOOKING_ID/cancel \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{"reason": "Plans changed"}' | jq .
response = requests.post(
f"{BASE_URL}/bookings/{booking_id}/cancel",
headers={"X-API-Key": API_KEY, "Content-Type": "application/json"},
json={"reason": "Plans changed"},
)
if response.status_code == 200:
print(f"Cancelled: {response.json()['status']}")
else:
print(f"Cannot cancel: {response.json()['error']}")
const response = await fetch(`${BASE_URL}/bookings/${bookingId}/cancel`, {
method: "POST",
headers: { "X-API-Key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ reason: "Plans changed" }),
});
if (response.ok) {
console.log(`Cancelled: ${(await response.json()).status}`);
} else {
console.log(`Cannot cancel: ${(await response.json()).error}`);
}
cancelBody, _ := json.Marshal(map[string]string{"reason": "Plans changed"})
req, _ := http.NewRequest("POST", baseURL+"/bookings/"+bookingID+"/cancel",
bytes.NewReader(cancelBody))
req.Header.Set("X-API-Key", apiKey)
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("Status: %s\n", result["status"])