{
  "info": {
    "name": "MobiTrack24 — Vehicle Location API",
    "description": "Live GPS vehicle locations from the MobiTrack24 platform.\n\n**Before running anything**, open the collection's *Variables* tab and fill in\n`organization_name`, `email` and `api_key`. Every request reads them from there,\nso you set them once.\n\nGet a key at https://api.mobitrack24.com/portal/dashboard — full reference at\nhttps://api.mobitrack24.com/portal/docs.\n\nEach request ships with tests. Use *Run collection* to check an integration\nend to end: the happy paths assert the response schema, and the error folder\nasserts that failures stay inside the same JSON envelope.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://api.mobitrack24.com/v1",
      "type": "string"
    },
    {
      "key": "organization_name",
      "value": "",
      "type": "string"
    },
    {
      "key": "email",
      "value": "",
      "type": "string"
    },
    {
      "key": "api_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "vehicle_id",
      "value": "VEH001",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "Fleet locations",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/vehicles/current-location?organization_name={{organization_name}}&email={{email}}&api_key={{api_key}}",
          "protocol": "https",
          "host": [
            "api",
            "mobitrack24",
            "com"
          ],
          "path": [
            "v1",
            "vehicles",
            "current-location"
          ],
          "query": [
            {
              "key": "organization_name",
              "value": "{{organization_name}}",
              "description": "Registered organization name."
            },
            {
              "key": "email",
              "value": "{{email}}",
              "description": "Registered email address."
            },
            {
              "key": "api_key",
              "value": "{{api_key}}",
              "description": "Your issued API key."
            }
          ]
        },
        "description": "Latest position of every vehicle the organization manages.\n\nOmitting `vehicle_id` is what makes this the fleet call. A vehicle that has\nnever reported a position has no location to send, so it appears in neither\n`data` nor `vehicle_count`."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "",
              "pm.test(\"responds as JSON with a success flag\", () => {",
              "    pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");",
              "    pm.expect(body).to.have.property(\"success\");",
              "});",
              "",
              "pm.test(\"carries CORS headers\", () => {",
              "    pm.expect(pm.response.headers.get(\"Access-Control-Allow-Origin\")).to.eql(\"*\");",
              "});",
              "",
              "pm.test(\"returns 200\", () => pm.response.to.have.status(200));",
              "",
              "pm.test(\"vehicle_count matches the data array\", () => {",
              "    pm.expect(body.success).to.be.true;",
              "    pm.expect(body.data).to.be.an(\"array\");",
              "    pm.expect(body.vehicle_count).to.eql(body.data.length);",
              "});",
              "",
              "pm.test(\"every vehicle carries a usable fix\", () => {",
              "    body.data.forEach((vehicle) => {",
              "        pm.expect(vehicle.vehicle_id, \"vehicle_id\").to.be.a(\"string\").and.not.empty;",
              "        pm.expect(vehicle.speed, \"speed\").to.be.a(\"number\");",
              "        pm.expect(vehicle.heading, \"heading\").to.be.within(0, 360);",
              "        pm.expect(vehicle.ignition_status).to.be.oneOf([\"ON\", \"OFF\", \"UNAVAILABLE\"]);",
              "        pm.expect(vehicle.location.latitude, \"latitude\").to.be.within(-90, 90);",
              "        pm.expect(vehicle.location.longitude, \"longitude\").to.be.within(-180, 180);",
              "        pm.expect(Number.isNaN(Date.parse(vehicle.timestamp)), \"timestamp\").to.be.false;",
              "    });",
              "});",
              "",
              "// Hand the first vehicle to the single-vehicle request below.",
              "if (body.data && body.data.length > 0) {",
              "    pm.collectionVariables.set(\"vehicle_id\", body.data[0].vehicle_id);",
              "}"
            ]
          }
        }
      ],
      "response": []
    },
    {
      "name": "Single vehicle",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/vehicles/current-location?organization_name={{organization_name}}&email={{email}}&api_key={{api_key}}&vehicle_id={{vehicle_id}}",
          "protocol": "https",
          "host": [
            "api",
            "mobitrack24",
            "com"
          ],
          "path": [
            "v1",
            "vehicles",
            "current-location"
          ],
          "query": [
            {
              "key": "organization_name",
              "value": "{{organization_name}}",
              "description": "Registered organization name."
            },
            {
              "key": "email",
              "value": "{{email}}",
              "description": "Registered email address."
            },
            {
              "key": "api_key",
              "value": "{{api_key}}",
              "description": "Your issued API key."
            },
            {
              "key": "vehicle_id",
              "value": "{{vehicle_id}}",
              "description": "A single vehicle to return."
            }
          ]
        },
        "description": "The same endpoint narrowed to one vehicle, in the original v1 shape:\n`data` is an object rather than an array, without `vehicle_count`,\n`vehicle_name` or `registration_number`.\n\n`vehicle_id` is set automatically by the *Fleet locations* request, so run\nthat one first — or type an ID into the collection variables."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "",
              "pm.test(\"responds as JSON with a success flag\", () => {",
              "    pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");",
              "    pm.expect(body).to.have.property(\"success\");",
              "});",
              "",
              "pm.test(\"carries CORS headers\", () => {",
              "    pm.expect(pm.response.headers.get(\"Access-Control-Allow-Origin\")).to.eql(\"*\");",
              "});",
              "",
              "pm.test(\"returns 200\", () => pm.response.to.have.status(200));",
              "",
              "pm.test(\"data is a single vehicle object\", () => {",
              "    pm.expect(body.success).to.be.true;",
              "    pm.expect(body.data).to.be.an(\"object\").and.not.an(\"array\");",
              "    pm.expect(body.data.vehicle_id).to.eql(pm.collectionVariables.get(\"vehicle_id\"));",
              "});"
            ]
          }
        }
      ],
      "response": []
    },
    {
      "name": "Error cases",
      "description": "Failures a client has to handle. Each one is expected to fail — the tests assert the failure is well formed, not that the call succeeded.",
      "item": [
        {
          "name": "400 — missing parameter",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/vehicles/current-location?",
              "protocol": "https",
              "host": [
                "api",
                "mobitrack24",
                "com"
              ],
              "path": [
                "v1",
                "vehicles",
                "current-location"
              ],
              "query": [
                {
                  "key": "organization_name",
                  "value": "{{organization_name}}",
                  "disabled": true
                },
                {
                  "key": "email",
                  "value": "{{email}}",
                  "disabled": true
                },
                {
                  "key": "api_key",
                  "value": "{{api_key}}",
                  "disabled": true
                }
              ]
            },
            "description": "Sends no credentials at all."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "",
                  "pm.test(\"responds as JSON with a success flag\", () => {",
                  "    pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");",
                  "    pm.expect(body).to.have.property(\"success\");",
                  "});",
                  "",
                  "pm.test(\"carries CORS headers\", () => {",
                  "    pm.expect(pm.response.headers.get(\"Access-Control-Allow-Origin\")).to.eql(\"*\");",
                  "});",
                  "",
                  "pm.test(\"returns 400\", () => pm.response.to.have.status(400));",
                  "pm.test(\"names the missing parameter\", () => {",
                  "    pm.expect(body.success).to.be.false;",
                  "    pm.expect(body.message).to.include(\"Missing required parameter\");",
                  "});"
                ]
              }
            }
          ],
          "response": []
        },
        {
          "name": "401 — wrong key",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/vehicles/current-location?organization_name={{organization_name}}&email={{email}}&api_key=definitely-not-a-valid-key",
              "protocol": "https",
              "host": [
                "api",
                "mobitrack24",
                "com"
              ],
              "path": [
                "v1",
                "vehicles",
                "current-location"
              ],
              "query": [
                {
                  "key": "organization_name",
                  "value": "{{organization_name}}"
                },
                {
                  "key": "email",
                  "value": "{{email}}"
                },
                {
                  "key": "api_key",
                  "value": "definitely-not-a-valid-key"
                }
              ]
            },
            "description": "Correct identity, invalid key."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "",
                  "pm.test(\"responds as JSON with a success flag\", () => {",
                  "    pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");",
                  "    pm.expect(body).to.have.property(\"success\");",
                  "});",
                  "",
                  "pm.test(\"carries CORS headers\", () => {",
                  "    pm.expect(pm.response.headers.get(\"Access-Control-Allow-Origin\")).to.eql(\"*\");",
                  "});",
                  "",
                  "pm.test(\"returns 401\", () => pm.response.to.have.status(401));",
                  "pm.test(\"does not leak why\", () => {",
                  "    pm.expect(body.success).to.be.false;",
                  "    pm.expect(body.message).to.eql(\"Unauthorized.\");",
                  "});"
                ]
              }
            }
          ],
          "response": []
        },
        {
          "name": "404 — unknown vehicle",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/vehicles/current-location?organization_name={{organization_name}}&email={{email}}&api_key={{api_key}}&vehicle_id=VEH-DOES-NOT-EXIST",
              "protocol": "https",
              "host": [
                "api",
                "mobitrack24",
                "com"
              ],
              "path": [
                "v1",
                "vehicles",
                "current-location"
              ],
              "query": [
                {
                  "key": "organization_name",
                  "value": "{{organization_name}}",
                  "description": "Registered organization name."
                },
                {
                  "key": "email",
                  "value": "{{email}}",
                  "description": "Registered email address."
                },
                {
                  "key": "api_key",
                  "value": "{{api_key}}",
                  "description": "Your issued API key."
                },
                {
                  "key": "vehicle_id",
                  "value": "VEH-DOES-NOT-EXIST"
                }
              ]
            },
            "description": "A vehicle_id outside the key's scope."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "",
                  "pm.test(\"responds as JSON with a success flag\", () => {",
                  "    pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/json\");",
                  "    pm.expect(body).to.have.property(\"success\");",
                  "});",
                  "",
                  "pm.test(\"carries CORS headers\", () => {",
                  "    pm.expect(pm.response.headers.get(\"Access-Control-Allow-Origin\")).to.eql(\"*\");",
                  "});",
                  "",
                  "pm.test(\"returns 404\", () => pm.response.to.have.status(404));",
                  "pm.test(\"says the vehicle was not found\", () => {",
                  "    pm.expect(body.success).to.be.false;",
                  "    pm.expect(body.message).to.eql(\"Vehicle not found.\");",
                  "});"
                ]
              }
            }
          ],
          "response": []
        }
      ]
    }
  ]
}
