Hoppa till huvudinnehåll

Lesson 3.5 Postman

Postman is a graphical HTTP client for exploring and calling the IoT platform's REST API - logging in, reading devices, pushing data, and running saved request collections. In this lesson you'll authenticate, read your devices, push a value, and (optionally) bulk-import time series.

The full API is documented in Swagger (https://staging.yggio.net/swagger).

Before you start

  • Install Postman.
  • An IoT platform account (username + password).
  • Optional: create a Postman environment with variables baseUrl = https://staging.yggio.net and (later) token, so requests read {{baseUrl}} and {{token}}.

Exercise 1 - Get an access token

  1. New request → POST {{baseUrl}}/api/auth/local.
  2. Body → raw → JSON:
    { "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD" }
  3. Send. The response contains a token. Copy it (or, in the Tests tab, save it automatically: pm.environment.set("token", pm.response.json().token)).

All authenticated calls use the header Authorization: Bearer <token>.

Exercise 2 - List your devices

  1. New request → GET {{baseUrl}}/api/iotnodes.
  2. Headers: Authorization: Bearer {{token}}.
  3. Send - you get every device with its current fields. Add a query to filter, e.g. {{baseUrl}}/api/iotnodes?q=temperature for devices that have a temperature field.

Exercise 3 - Push a value to a generic device

  1. In the IoT platform, create a Generic device with a secret (see Lesson 2.3). The secret is an API key - keep it private.
  2. New request → POST {{baseUrl}}/http-push/generic?identifier=secret.
  3. Headers: Content-Type: application/json.
  4. Body → raw → JSON (include the secret):
    { "secret": "YOURDEVICESECRET", "temperature": 22 }
  5. Send - the device updates in the IoT platform. (This endpoint uses the device secret, not the Bearer token.)

Exercise 4 - Bulk-import time series from a CSV (optional)

The IoT platform ships a ready-made Postman collection that reads a CSV and posts each row as a timestamped reading - see Lesson 1.4 for the full walkthrough. In short:

  1. Import the CSV-import collection.
  2. Add a temporary secret to the target device via PUT {{baseUrl}}/api/iotnodes/{_id}.
  3. Point the collection at your CSV and set the secret in the request body, then Run the collection.
  4. Remove the temporary secret afterwards (PUT …/api/iotnodes/{_id} with { "secret": "$unset" }).

⚠️ Imported time-series data cannot be changed or removed - test with a small file first.

What you learned

  • How to get a token from POST /api/auth/local and use Authorization: Bearer.
  • How to read devices (GET /api/iotnodes) and push data (POST /http-push/generic).
  • Where to find the CSV time-series import collection.

Where next