If you have ever stared at the OCPI 2.2.1 spec trying to reverse-engineer what an actual request looks like, this article is the shortcut. Below are copy-paste-ready examples for Locations, Sessions, and CDRs, the three modules a first integration has to get working. Each one gives you the HTTP method, the endpoint path, the headers that matter, and a fully populated JSON body.

Reading a payload is one thing; watching it move between a CPO and an eMSP is another. Once you have the shapes below in your head, try the interactive OCPI Simulator to replay the credentials handshake and watch objects like these move between a CPO and an eMSP, step by step. The handshake is the part that is hardest to picture from a static example, and the credentials and versions walkthrough covers what the two parties swap before any request below is even legal.
The parts every OCPI request shares
Before the module-specific bodies, three things are constant across almost every OCPI call. Each of them fails in a way that looks like a body problem when it is not.
The endpoint is versioned and role-scoped. OCPI URLs are not fixed; you discover them from the other party’s versions endpoint during the handshake. They do follow a predictable shape:
https://cpo.example.com/ocpi/cpo/2.2.1/locations
https://emsp.example.com/ocpi/emsp/2.2.1/sessions
The cpo or emsp segment is a convention, not a rule; always use the URL the version details gave you. What it reflects is real, though: every functional module has two interfaces. The Sender interface is hosted by the party that owns the data, and the other side pulls from it. The Receiver interface is hosted by the other party, and the owner pushes to it. For Locations, Sessions and CDRs the CPO owns the data, so pulls go to the CPO’s URLs and pushes go to the eMSP’s.
Three headers are mandatory. After credentials are exchanged, every functional request carries:
Authorization: Token <base64-token>
X-Request-ID: <new unique id for this request>
X-Correlation-ID: <id shared by every request in this conversation>
The response echoes the same X-Request-ID and X-Correlation-ID. Both are required in 2.2.1, and the correlation ID is what lets you find one session’s traffic in your log and in your partner’s. When a hub or another multi-party platform sits between the two sides, functional requests also need the four routing headers (OCPI-from-country-code, OCPI-from-party-id, OCPI-to-country-code, OCPI-to-party-id), so the platform knows who sent the message and where to deliver it.
The word Token is literal (it is the scheme name, not the value), and in OCPI 2.2 and later the token itself is base64-encoded. Skip the encoding and the server rejects the call with a 401 before it reads a single byte of your body.
Responses are wrapped in an envelope. You never get a bare object back. OCPI wraps every response body:
{
"data": { },
"status_code": 1000,
"status_message": "Success",
"timestamp": "2026-07-12T09:30:00Z"
}
data holds an object on single-object endpoints and an array on list endpoints. status_code is the OCPI-level verdict: 1000 is success, the 2xxx range is a client-side error, and 3xxx is a server-side one.
So check status_code, not just the HTTP status. A 200 OK carrying status_code: 2001 means your request arrived intact and was refused anyway. The OCPI overview explains where this two-layer design comes from, and the error response reference lists what each range actually signals.
Locations: a GET request and its response
Locations is the map: where the stations are, what connectors they have, whether they are live. The CPO hosts it and the eMSP consumes it, either by polling on a schedule or by receiving pushes (the tradeoff is laid out in pull versus push patterns). A paginated pull looks like this:
GET /ocpi/cpo/2.2.1/locations?date_from=2026-07-01T00:00:00Z&limit=50 HTTP/1.1
Host: cpo.example.com
Authorization: Token bXktc2VjcmV0LXRva2Vu
X-Request-ID: 3c9d2a10-6e4f-4b8a-9f21-7d5e0c8b1a42
X-Correlation-ID: 3c9d2a10-6e4f-4b8a-9f21-7d5e0c8b1a42
Accept: application/json
The date_from filter and limit are how you page through a large catalog without re-pulling everything. Paging information comes back in headers, not in the body:
HTTP/1.1 200 OK
Content-Type: application/json
X-Request-ID: 3c9d2a10-6e4f-4b8a-9f21-7d5e0c8b1a42
X-Correlation-ID: 3c9d2a10-6e4f-4b8a-9f21-7d5e0c8b1a42
X-Total-Count: 1284
X-Limit: 50
Link: <https://cpo.example.com/ocpi/cpo/2.2.1/locations?offset=50&limit=50&date_from=2026-07-01T00:00:00Z>; rel="next"
X-Total-Count is the number of matching Locations across all pages, X-Limit is the page size the CPO actually applied (it can be lower than what you asked for), and Link is the next page, with your filters carried over. Keep following Link until a response has none. The body is the usual envelope with data holding an array of Location objects; here is one, with the required fields plus a few useful optional ones:
{
"country_code": "US",
"party_id": "EVC",
"id": "LOC_10021",
"publish": true,
"name": "Downtown Garage - Level 3",
"address": "425 Market Street",
"city": "San Francisco",
"postal_code": "94105",
"state": "CA",
"country": "USA",
"coordinates": {
"latitude": "37.79130",
"longitude": "-122.39690"
},
"evses": [
{
"uid": "EVSE_10021_1",
"evse_id": "US*EVC*E10021001",
"status": "AVAILABLE",
"connectors": [
{
"id": "1",
"standard": "IEC_62196_T1_COMBO",
"format": "CABLE",
"power_type": "DC",
"max_voltage": 920,
"max_amperage": 500,
"max_electric_power": 350000,
"tariff_ids": ["TARIFF_DC_PEAK"],
"last_updated": "2026-07-11T18:04:00Z"
}
],
"last_updated": "2026-07-11T18:04:00Z"
}
],
"time_zone": "America/Los_Angeles",
"last_updated": "2026-07-11T18:04:00Z"
}
A few things worth internalizing: evse_id (the roaming-visible identifier) is different from uid (the internal, opaque key you use in URLs). status lives on the EVSE, not the connector. And max_electric_power is in watts, so a 350 kW connector reads 350000, not 350. The full field map, including the many optional facility and image fields, is in the Locations module deep-dive.
Sessions: pushing a live session with PUT and PATCH
A Session is a living object. The CPO creates it on the eMSP with a full PUT the moment charging starts, then streams updates with PATCH. Here is the initial push:
PUT /ocpi/emsp/2.2.1/sessions/US/EVC/SESSION_45501 HTTP/1.1
Host: emsp.example.com
Authorization: Token bXktc2VjcmV0LXRva2Vu
X-Request-ID: 8f14e45f-ceea-4c6b-9a3b-1d2e3f4a5b6c
X-Correlation-ID: 6b1d9e2a-4c3f-4e8a-8b7d-2f9a0c1e5d34
Content-Type: application/json
{
"country_code": "US",
"party_id": "EVC",
"id": "SESSION_45501",
"start_date_time": "2026-07-12T09:15:00Z",
"kwh": 0,
"cdr_token": {
"country_code": "DE",
"party_id": "MSP",
"uid": "04A1B2C3D4E580",
"type": "RFID",
"contract_id": "DE-MSP-C12345678-9"
},
"auth_method": "AUTH_REQUEST",
"location_id": "LOC_10021",
"evse_uid": "EVSE_10021_1",
"connector_id": "1",
"currency": "USD",
"status": "ACTIVE",
"last_updated": "2026-07-12T09:15:00Z"
}
Note that the URL carries the country_code, party_id, and session id as path segments; that trio is what uniquely addresses the object, and it must match the same three fields in the body. In cdr_token, uid is what the RFID reader actually read and contract_id is the driver’s contract; they are different values, and the eMSP looks the driver up by uid plus type. The eMSP answers the PUT with an envelope and nothing in data:
{
"status_code": 1000,
"status_message": "Success",
"timestamp": "2026-07-12T09:15:01Z"
}
Once the session is live, the CPO does not re-send the whole thing. It sends only what changed:
PATCH /ocpi/emsp/2.2.1/sessions/US/EVC/SESSION_45501 HTTP/1.1
Host: emsp.example.com
Authorization: Token bXktc2VjcmV0LXRva2Vu
X-Request-ID: 2a7b9c4d-1e3f-4a5b-8c6d-9e0f1a2b3c4d
X-Correlation-ID: 6b1d9e2a-4c3f-4e8a-8b7d-2f9a0c1e5d34
Content-Type: application/json
{
"kwh": 18.4,
"status": "ACTIVE",
"last_updated": "2026-07-12T09:34:12Z"
}
That last_updated field is doing real work. If two PATCH requests arrive out of order, which a busy connection makes entirely possible, the eMSP compares timestamps and discards the older one, so the session never appears to “go backwards.” last_updated is also mandatory on every PATCH in 2.2.1, so a PATCH without it should be rejected with status_code 2001. And if a PATCH carries charging_periods, the receiver adds them to the periods it already has rather than replacing the list, so send only the new ones. Building the receiver correctly means treating last_updated as the tiebreaker, a point the Sessions module walkthrough covers in depth. The running kwh and total_cost in a Session are estimates; the authoritative billing number arrives later, in the CDR.
CDRs: posting the final billing record
When a session ends, the CPO posts a Charge Detail Record, the immutable billable summary. Unlike Sessions, a CDR is created once with a POST and never modified:
POST /ocpi/emsp/2.2.1/cdrs HTTP/1.1
Host: emsp.example.com
Authorization: Token bXktc2VjcmV0LXRva2Vu
X-Request-ID: 7e8f9a0b-1c2d-4e3f-a4b5-c6d7e8f9a0b1
X-Correlation-ID: 6b1d9e2a-4c3f-4e8a-8b7d-2f9a0c1e5d34
Content-Type: application/json
{
"country_code": "US",
"party_id": "EVC",
"id": "CDR_88120",
"start_date_time": "2026-07-12T09:15:00Z",
"end_date_time": "2026-07-12T09:42:33Z",
"session_id": "SESSION_45501",
"cdr_token": {
"country_code": "DE",
"party_id": "MSP",
"uid": "04A1B2C3D4E580",
"type": "RFID",
"contract_id": "DE-MSP-C12345678-9"
},
"auth_method": "AUTH_REQUEST",
"cdr_location": {
"id": "LOC_10021",
"address": "425 Market Street",
"city": "San Francisco",
"postal_code": "94105",
"country": "USA",
"evse_uid": "EVSE_10021_1",
"evse_id": "US*EVC*E10021001",
"connector_id": "1",
"connector_standard": "IEC_62196_T1_COMBO",
"connector_format": "CABLE",
"connector_power_type": "DC",
"coordinates": { "latitude": "37.79130", "longitude": "-122.39690" }
},
"currency": "USD",
"tariffs": [
{
"country_code": "US",
"party_id": "EVC",
"id": "TARIFF_DC_PEAK",
"currency": "USD",
"elements": [
{ "price_components": [ { "type": "ENERGY", "price": 0.60, "vat": 10.0, "step_size": 1 } ] }
],
"last_updated": "2026-07-01T00:00:00Z"
}
],
"charging_periods": [
{
"start_date_time": "2026-07-12T09:15:00Z",
"dimensions": [ { "type": "ENERGY", "volume": 42.7 } ]
}
],
"total_cost": { "excl_vat": 25.62, "incl_vat": 28.18 },
"total_energy": 42.7,
"total_energy_cost": { "excl_vat": 25.62, "incl_vat": 28.18 },
"total_time": 0.459,
"last_updated": "2026-07-12T09:42:40Z"
}
The numbers check out against the snapshotted tariff, which is the test an eMSP’s reconciliation job runs on every CDR: 42.7 kWh × 0.60 = 25.62 excluding tax, and 25.62 × 1.10 = 28.182, rounded to 28.18. A step_size of 1 on an ENERGY component means billing per Wh, so nothing is rounded up before the multiplication.
The eMSP’s answer carries the URL where it stored the CDR:
HTTP/1.1 201 Created
Content-Type: application/json
Location: https://emsp.example.com/ocpi/emsp/2.2.1/cdrs/CDR_88120
X-Request-ID: 7e8f9a0b-1c2d-4e3f-a4b5-c6d7e8f9a0b1
X-Correlation-ID: 6b1d9e2a-4c3f-4e8a-8b7d-2f9a0c1e5d34
{
"status_code": 1000,
"status_message": "Success",
"timestamp": "2026-07-12T09:42:41Z"
}
The Location header is required for this response. Store it: it is how the CPO can fetch that one CDR back from the eMSP later. The spec says the receiver SHOULD answer 201 Created for a new object (200 for an update), but many eMSPs answer 200 OK, so a CPO should treat any 2xx as delivered.
The CDR snapshots everything it needs to stand alone: the location, the tariff that applied, and each charging period. That is deliberate: a CDR must remain valid and auditable even after the live Location or Tariff it was built from has changed. And because it is immutable, corrections are not edits. To fix a CDR you post a credit CDR that references the original, a pattern explained fully in the CDRs module guide. Note that cdr_location is a compact snapshot with its own field set rather than a full Location object, so code that deserializes both into the same class will break on the first CDR it sees.
Tokens: a real-time authorization and its answer
The one request in a first integration that goes from the CPO to the eMSP and expects a decision back is real-time authorization. A driver taps an RFID card whose token the CPO has not cached (or whose whitelist is NEVER), and the CPO asks the eMSP:
POST /ocpi/emsp/2.2.1/tokens/04A1B2C3D4E580/authorize?type=RFID HTTP/1.1
Host: emsp.example.com
Authorization: Token bXktc2VjcmV0LXRva2Vu
X-Request-ID: 0d1e2f3a-4b5c-4d6e-8f7a-9b0c1d2e3f4a
X-Correlation-ID: 6b1d9e2a-4c3f-4e8a-8b7d-2f9a0c1e5d34
Content-Type: application/json
{
"location_id": "LOC_10021",
"evse_uids": ["EVSE_10021_1"]
}
The body is a LocationReferences object and is optional, but leave it out and an eMSP that needs to know where the driver is may answer status_code 2002 (not enough information). The type query parameter defaults to RFID when omitted; send it anyway. The answer is an AuthorizationInfo object:
{
"data": {
"allowed": "ALLOWED",
"token": {
"country_code": "DE",
"party_id": "MSP",
"uid": "04A1B2C3D4E580",
"type": "RFID",
"contract_id": "DE-MSP-C12345678-9",
"issuer": "Example eMSP",
"valid": true,
"whitelist": "ALLOWED",
"last_updated": "2026-07-01T08:00:00Z"
},
"location": {
"location_id": "LOC_10021",
"evse_uids": ["EVSE_10021_1"]
},
"authorization_reference": "AUTH-2026-07-12-0042"
},
"status_code": 1000,
"status_message": "Success",
"timestamp": "2026-07-12T09:14:58Z"
}
allowed is one of ALLOWED, BLOCKED, EXPIRED, NO_CREDIT or NOT_ALLOWED. If the eMSP has never heard of the token, the 2.2.1 Tokens module requires HTTP 404 with status_code 2004 and no data, and the CPO refuses the charge (see the Tokens module guide). When authorization_reference comes back, the CPO has to copy it into the Session and the CDR for this charge; it is the eMSP’s only reliable way to tie the bill to this exact authorization.
Why these break, and how to see it live
Reading three well-formed requests makes OCPI look easy. Everything above is correct, and that is precisely what hides the ways it goes wrong:
- Missing or unencoded
Authorizationtoken. You get a401. Dropping the scheme wordTokengives the same 401, because the server can no longer match the header to a known party. - Path/body mismatch, where the
idin the URL disagrees with theidin the body on a Session PUT. - Wrong role in the path, such as pushing a Session to the CPO’s Sender URL instead of the eMSP’s Receiver URL from version details.
- Ignoring
status_code: a200 OKwithstatus_code: 2001is logged as a success and the object silently never lands. - Applying a stale PATCH, because the receiving side never compares
last_updated.
None of these surface until you send a real request at a real counterparty. The OCPI Simulator replays a correct exchange so you know what to expect; then send these bodies to a test endpoint, break a header on purpose and see which status_code you get. The connection test guide has the exact steps. Before you send your own bodies, paste them into the OCPI Message Checker, which flags the fields a partner would reject.
One thing worth carrying away from all this JSON: the payloads are the easy half. Every object above is a snapshot of state that was true at one last_updated instant, and most of the protocol is a set of rules about which snapshot wins when two of them disagree. Get that ordering right and malformed bodies become a schema problem you can catch once. Get it wrong and you ship an integration that validates perfectly and bills the wrong number, a failure no schema check can see. The common integration pitfalls writeup collects the ones that survive a clean validation pass.