---
updatedAt: 2026-05-27T10:18:53.000Z
agentTools:
  projectIndex: https://gethapn.readme.io/llms.txt
---

# Get the latest message of the device

Get the last message of the specified device.

# OpenAPI definition

```json
{
  "openapi": "3.0.3",
  "info": {
    "description": "The Hapn API is an HTTP interface for managing devices, accounts, and cloud data.",
    "version": "1.0.0",
    "title": "Hapn API",
    "termsOfService": "https://gethapn.com/terms",
    "contact": {
      "name": "Dev",
      "email": "developer@gethapn.com",
      "url": "http://gethapn.com"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "servers": [
    {
      "url": "https://api.iotgps.io/v1",
      "description": "Prod"
    },
    {
      "url": "https://api-dev.iotgps.io/v1",
      "description": "Dev"
    }
  ],
  "paths": {
    "/messages/latest/{imei}": {
      "get": {
        "summary": "Get the latest message of the device",
        "tags": [
          "Messages"
        ],
        "parameters": [
          {
            "name": "imei",
            "in": "path",
            "required": true,
            "description": "IMEI of the device",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Latest message result",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/PaginatedSuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "result": {
                          "$ref": "#/components/schemas/Message"
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "example-1": {
                    "value": {
                      "success": true,
                      "message": "ok",
                      "result": {
                        "type": "GTSOS",
                        "gpsUTCTime": "20210817215336",
                        "imei": "868239050345326",
                        "latitude": 40.830866,
                        "longitude": -74.117153,
                        "altitude": 100,
                        "odoMileage": 0,
                        "sendTime": "2021-08-17T21:53:36.000Z",
                        "messageId": "09e75b48-f04b-42b0-8ee1-e9c9eb5e8780",
                        "speed": 0,
                        "batteryPercentage": null
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenDevice"
          },
          "404": {
            "$ref": "#/components/responses/MessageNotFound"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        },
        "operationId": "get-latest-message",
        "description": "Get the last message of the specified device."
      }
    }
  },
  "components": {
    "schemas": {
      "Message": {
        "description": "A message emitted by a device",
        "type": "object",
        "x-examples": {
          "example-1": {
            "type": "GTFRI",
            "gpsUTCTime": "20210818122718",
            "imei": "868239050345326",
            "latitude": 40.830728,
            "longitude": -74.11678,
            "odoMileage": 0,
            "sendTime": "2021-08-18T12:28:27.000Z",
            "messageId": "dd65492e-b178-4fa6-8cd1-f771df205b44",
            "speed": 0,
            "value": {
              "type": "GTFRI",
              "gpsUTCTime": "20210818122718",
              "imei": "868239050345326",
              "latitude": 40.830728,
              "longitude": -74.11678,
              "altitude": 100,
              "odoMileage": 0,
              "sendTime": "2021-08-18T12:28:27.000Z",
              "messageId": "dd65492e-b178-4fa6-8cd1-f771df205b44",
              "speed": 0,
              "batteryPercentage": 81
            }
          }
        },
        "title": "",
        "properties": {
          "messageId": {
            "type": "string",
            "minLength": 1,
            "description": "Unique ID of this message"
          },
          "imei": {
            "type": "string",
            "minLength": 1,
            "description": "IMEI of the device"
          },
          "type": {
            "type": "string",
            "minLength": 1,
            "description": "Message type"
          },
          "sendTime": {
            "type": "string",
            "minLength": 1,
            "description": "Time at which message was sent"
          },
          "gpsUTCTime": {
            "type": "string"
          },
          "latitude": {
            "description": "Latitude of the device",
            "type": "number",
            "nullable": true
          },
          "longitude": {
            "type": "number",
            "nullable": true,
            "description": "Longitude of the device"
          },
          "altitude": {
            "type": "number",
            "nullable": true,
            "description": "Altitude of the device"
          },
          "odoMileage": {
            "type": "number",
            "nullable": true,
            "description": "Odometer mileage"
          },
          "speed": {
            "type": "number",
            "nullable": true,
            "description": "Current speed"
          },
          "batteryPercentage": {
            "type": "number",
            "nullable": true,
            "description": "Current device battery percentage. Some message types don't send this information."
          },
          "ignition": {
            "type": "string",
            "enum": [
              "ON",
              "OFF"
            ],
            "description": "If the message is of type ignitionOn or ignitionOff, undefined otherwise"
          }
        },
        "required": [
          "messageId",
          "imei",
          "type",
          "sendTime"
        ]
      },
      "PaginatedSuccessResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "properties": {
              "items": {
                "type": "array"
              },
              "nextToken": {
                "type": "string"
              }
            },
            "required": [
              "items"
            ]
          }
        },
        "required": [
          "message",
          "success",
          "result"
        ],
        "x-examples": {
          "example-1": {
            "value": {
              "success": true,
              "message": "string",
              "result": {
                "items": [
                  {
                    "imei": "12345"
                  }
                ],
                "nextToken": "eyJzZW5kVGltZSI6IjIwMjEtMDgtMThUMTU6MTc6NTAuMDAwWiIsImNsaWVudElkIjo2MDY2MDksIm1lc3NhZ2VfaWQiOiI2ZTMwYzczMS1iMGNhLTQwMzgtYjY1Zi1kM2Y1NGZlMWQ0ZjUifQ=="
              }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "success",
          "message"
        ],
        "x-examples": {
          "example-1": {
            "value": {
              "success": false,
              "message": "Unauthorized"
            }
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Unauthorized"
                }
              }
            }
          }
        }
      },
      "ForbiddenDevice": {
        "description": "Unauthorized device",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Unauthorized device"
                }
              }
            }
          }
        }
      },
      "Error": {
        "description": "Server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Error"
                }
              }
            }
          }
        }
      },
      "MessageNotFound": {
        "description": "The specified message was not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Message Not Found"
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "https://auth.usehapn.com/oauth2/token",
            "scopes": {}
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Messages",
      "description": "Messages sent by devices"
    }
  ],
  "security": [
    {
      "OAuth2": []
    }
  ]
}
```