{
  "info": {
    "name": "SimpleGPS API v1",
    "description": "Read the vehicles on your account and the hours they ran.\n\nSetup:\n1. Issue a key in SimpleGPS under Settings, API keys. It is shown once.\n2. Open this collection's Variables tab and paste it into api_key.\n3. If your account is on simplegps.bg, change base_url to https://simplegps.bg.\n4. Run 'Devices' first and copy an id into the device_id variable.\n\nEvery duration is in seconds, not hours. engine_seconds is the sum of moving_seconds and idle_seconds, not a third measurement.\n\nFull reference: https://simple-gps.com/api/docs",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{api_key}}", "type": "string" }]
  },
  "variable": [
    { "key": "base_url", "value": "https://simple-gps.com", "description": "Use https://simplegps.bg for a Bulgarian account." },
    { "key": "api_key", "value": "", "description": "From Settings, API keys. Starts with sgps_" },
    { "key": "device_id", "value": "", "description": "Any id from the Devices response." },
    { "key": "from", "value": "2026-08-01", "description": "Whole days in the vehicle's own timezone." },
    { "key": "to", "value": "2026-08-07" }
  ],
  "item": [
    {
      "name": "Devices",
      "request": {
        "method": "GET",
        "url": { "raw": "{{base_url}}/api/v1/devices", "host": ["{{base_url}}"], "path": ["api", "v1", "devices"] },
        "description": "Every vehicle on the account. Our id never changes, so map it once against your own asset id."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('200 OK', () => pm.response.to.have.status(200));",
              "",
              "// Saves the first vehicle so the other requests work without",
              "// anyone copying an id by hand.",
              "const body = pm.response.json();",
              "if (body.data && body.data.length) {",
              "    pm.collectionVariables.set('device_id', body.data[0].id);",
              "    console.log('device_id set to ' + body.data[0].id + ' (' + body.data[0].name + ')');",
              "} else {",
              "    console.log('No vehicles on this account yet.');",
              "}"
            ]
          }
        }
      ]
    },
    {
      "name": "Hours for a window",
      "request": {
        "method": "GET",
        "url": {
          "raw": "{{base_url}}/api/v1/devices/{{device_id}}/hours?from={{from}}&to={{to}}",
          "host": ["{{base_url}}"],
          "path": ["api", "v1", "devices", "{{device_id}}", "hours"],
          "query": [{ "key": "from", "value": "{{from}}" }, { "key": "to", "value": "{{to}}" }]
        },
        "description": "Totals for the window. Leave from and to out and you get the last seven days."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('200 OK', () => pm.response.to.have.status(200));",
              "",
              "// The one arithmetic mistake worth guarding against on your side:",
              "// engine is the sum of the other two, so adding all three double",
              "// counts every hour.",
              "const b = pm.response.json();",
              "pm.test('engine = moving + idle', () => {",
              "    pm.expect(b.engine_seconds).to.eql(b.moving_seconds + b.idle_seconds);",
              "});"
            ]
          }
        }
      ]
    },
    {
      "name": "Hours per day",
      "request": {
        "method": "GET",
        "url": {
          "raw": "{{base_url}}/api/v1/devices/{{device_id}}/hours/daily?from={{from}}&to={{to}}",
          "host": ["{{base_url}}"],
          "path": ["api", "v1", "devices", "{{device_id}}", "hours", "daily"],
          "query": [{ "key": "from", "value": "{{from}}" }, { "key": "to", "value": "{{to}}" }]
        },
        "description": "The same three numbers per day, in the vehicle's own timezone. This is usually what replaces a spreadsheet."
      }
    },
    {
      "name": "Meter (running total)",
      "request": {
        "method": "GET",
        "url": {
          "raw": "{{base_url}}/api/v1/devices/{{device_id}}/meter",
          "host": ["{{base_url}}"],
          "path": ["api", "v1", "devices", "{{device_id}}", "meter"]
        },
        "description": "Everything since the tracker was installed - the figure that lines up against the hour meter on the machine's dash."
      }
    },
    {
      "name": "Refused: no key",
      "request": {
        "auth": { "type": "noauth" },
        "method": "GET",
        "url": { "raw": "{{base_url}}/api/v1/devices", "host": ["{{base_url}}"], "path": ["api", "v1", "devices"] },
        "description": "Here so you can see what a refusal looks like before you meet one in production. Every refusal names its own fix rather than saying 'unauthorized'."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('401, and it says why', () => {",
              "    pm.response.to.have.status(401);",
              "    pm.expect(pm.response.json().error).to.be.a('string');",
              "});"
            ]
          }
        }
      ]
    }
  ]
}
