# OCPP Messages

## GET /api/ocpp-messages

Retrieve a list of OCPP (Open Charge Point Protocol) messages for a specific charger.

### Parameters

Parameters should be passed as query parameters on the URL.

* `chargerId` - **Required** The ID of the charger to retrieve messages for
* `startTimestamp` - ISO 8601 date string to filter to messages created after this time (defaults to 24 hours ago)
* `endTimestamp` - ISO 8601 date string to filter to messages created before this time (defaults to current time)
* `messageType` - Filter messages by message type. Can be a single message type (e.g., `messageType=Authorize`) or multiple message types (e.g., `messageType[]=StartTransaction&messageType[]=StopTransaction`).
* `limit` - Maximum number of messages to return per page (defaults to 50, maximum 500). This is a page size, not a cap on the total number of messages you can retrieve — paginate with `nextPageCursor` to fetch more.
* `nextPageCursor` - When the filters match more than one page of data, pass this parameter to fetch the next page. See [Pagination and Error Handling](/pagination-and-errors.md) for details on how pagination works.

The date range must be less than 8 days long. If you need more than 8 days of OCPP messages, please make multiple API requests.

### Response

Messages will be sorted with the newest first, so that by default when you call the endpoint you get the latest messages.

The JSON response will contain a `data` field with a list of OCPP messages matching the filters, and a `pagination` field containing pagination details.

```ts
{
  data: {
    id: number;
    createdAt: string; // ISO 8601 format
    ocppChargerIdentity: string;
    messageType: string; // OCPP message type (e.g., 'Authorize', 'StartTransaction', 'GetConfiguration')
    messagePayload: any; // The original OCPP message payload
    messageResponse: any; // The OCPP response or error message
    chargerId: number;
    protocol: string; // OCPP protocol version ('ocpp1.6' or 'ocpp2.0.1')
  }
  [];
  pagination: {
    hasNextPage: boolean;
    nextPageCursor: string | null;
  }
}
```

### Example request and response

Request:

```sh
curl "https://api.getflipturn.com/api/ocpp-messages?chargerId=123&startTimestamp=2024-04-30T01:00:07.321Z" -H "Authorization: Bearer {token}"
```

Filtering by a single message type:

```sh
curl "https://api.getflipturn.com/api/ocpp-messages?chargerId=123&messageType=Authorize" -H "Authorization: Bearer {token}"
```

Filtering by multiple message types:

```sh
curl "https://api.getflipturn.com/api/ocpp-messages?chargerId=123&messageType[]=StartTransaction&messageType[]=StopTransaction" -H "Authorization: Bearer {token}"
```

Response:

```js
{
  "data": [  {
    "id": 456,
    "createdAt": "2024-04-30T01:00:07.321Z",
    "ocppChargerIdentity": "test-charger-1",
    "messageType": "Authorize",
    "messagePayload": {
      "idTag": "test-tag-1"
    },
    "messageResponse": {
      "idTagInfo": {
        "status": "Accepted"
      }
    },
    "chargerId": 123,
    "protocol": "ocpp1.6"
  },
  {
    "id": 457,
    "createdAt": "2024-04-30T01:05:12.456Z",
    "ocppChargerIdentity": "test-charger-1",
    "messageType": "StartTransaction",
    "messagePayload": {
      "connectorId": 1
    },
    "messageResponse": {
      "transactionId": 12345
    },
    "chargerId": 123,
    "protocol": "ocpp1.6"
  }],
  "pagination": {
    "hasNextPage": false,
    "nextPageCursor": null
  }
}
```

### Message responses in case of error

Generally, both the request and response for each message is a JSON object. However, in special cases, the response can be a string only. For example:

* `FlipturnRequestTimeout` is used as the response if the request to the charger timed out
* `NotSupported` is used as the response if the charger or server doesn't support this message type

### Streaming export to Google Pub/Sub or Kafka

In addition to the REST API above, Flipturn supports exporting OCPP messages in real time to Google Pub/Sub or Apache Kafka. If you need a streaming integration, please reach out to us at <support@getflipturn.com> and we'll help you get set up.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-docs.getflipturn.com/ocpp-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
