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

# Get device metrics

Gets the device metrics within a date range. 

Device metrics are aggregations of specific device information over time. Ex.: distance traveled, time moving, time inside a boundary, etc.

# 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": {
    "/insights/metrics/{imei}": {
      "get": {
        "summary": "Get device metrics",
        "tags": [
          "Insights"
        ],
        "parameters": [
          {
            "name": "imei",
            "in": "path",
            "description": "IMEI to filter metrics by",
            "schema": {
              "type": "string"
            },
            "required": true,
            "example": "015181000672494"
          },
          {
            "schema": {
              "type": "string",
              "format": "date-time",
              "example": "2020-02-25T18:09:00Z"
            },
            "in": "query",
            "name": "startDate",
            "description": "Filter by metrics after startDate",
            "required": true
          },
          {
            "schema": {
              "type": "string",
              "format": "date-time",
              "example": "2020-02-26T18:09:00Z"
            },
            "in": "query",
            "name": "endDate",
            "description": "Filter by metrics before endDate",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Device metrics",
            "content": {
              "application/json": {
                "schema": {
                  "description": "",
                  "type": "object",
                  "$ref": "#/components/schemas/DeviceMetrics"
                },
                "examples": {
                  "example-1": {
                    "value": {
                      "success": true,
                      "message": "ok",
                      "result": {
                        "imei": "865134050130039",
                        "clientId": 128,
                        "metricActualStartDate": "2020-02-25T18:00:00Z",
                        "metricActualEndDate": "2020-02-25T22:00:00Z",
                        "timeMovingSeconds": 381,
                        "totalMessages": 179,
                        "distanceTraveledMiles": 1.576058702134033,
                        "timeInBoundaries": [
                          {
                            "boundaryId": 323151,
                            "duration": 33
                          },
                          {
                            "boundaryId": 331646,
                            "duration": 392
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        },
        "operationId": "get-device-metrics",
        "description": "Gets the device metrics within a date range. \n\nDevice metrics are aggregations of specific device information over time. Ex.: distance traveled, time moving, time inside a boundary, etc."
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "success",
          "message"
        ],
        "x-examples": {
          "example-1": {
            "value": {
              "success": false,
              "message": "Unauthorized"
            }
          }
        }
      },
      "DeviceMetrics": {
        "description": "A device metrics",
        "type": "object",
        "x-examples": {
          "example-1": {
            "imei": "865134050130039",
            "clientId": 128,
            "metricActualStartDate": "2020-02-25T18:00:00Z",
            "metricActualEndDate": "2020-02-25T22:00:00Z",
            "timeMovingSeconds": 381,
            "distanceTraveledMiles": 1.576058702134033,
            "timeInBoundaries": [
              {
                "boundaryId": 323151,
                "duration": 33
              },
              {
                "boundaryId": 331646,
                "duration": 392
              }
            ]
          }
        },
        "title": "Device metrics",
        "properties": {
          "imei": {
            "type": "string"
          },
          "clientId": {
            "type": "number"
          },
          "metricActualStartDate": {
            "type": "string",
            "format": "date-time"
          },
          "metricActualEndDate": {
            "type": "string",
            "format": "date-time"
          },
          "timeMovingSeconds": {
            "type": "number"
          },
          "totalMessages": {
            "type": "number"
          },
          "distanceTraveledMiles": {
            "type": "number"
          },
          "timeInBoundaries": {
            "type": "array",
            "description": "List of boundaries with the time passed inside the boundary",
            "items": {
              "type": "object",
              "properties": {
                "boundaryId": {
                  "type": "number"
                },
                "duration": {
                  "type": "number"
                }
              }
            }
          }
        },
        "required": [
          "imei",
          "clientId"
        ]
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Unauthorized"
                }
              }
            }
          }
        }
      },
      "Error": {
        "description": "Server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Error"
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "https://auth.usehapn.com/oauth2/token",
            "scopes": {}
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Insights",
      "description": "Account insights"
    }
  ],
  "security": [
    {
      "OAuth2": []
    }
  ]
}
```