API docs
Tools

Postman and OpenAPI

Every endpoint in a Postman collection, with saved example answers and sensor signing built in, and an OpenAPI 3.1 file for everything else.

Import into Postman

  1. In Postman, choose Import and drop in the collection and the environment.
  2. Pick the Ochio sandbox environment, and paste your key into apiKey. For a real site, change baseUrl to your Ochio server.
  3. Send Check health, then anything else.

The collection sends your key on every request. The two signed requests, a sensor's check-in and alert, need no key: a script signs them with sensorSecret, which Register a sensor fills in for you.

Requests that make something save its id for the next ones: register a sensor, send an alert, request a mission, and the requests after them use those ids.

The signing script
// Sign this request as the sensor: HMAC-SHA256 over "<timestamp>.<body>", keyed with {{sensorSecret}}.
const cryptoJs = require("crypto-js");
const secret = pm.variables.get("sensorSecret");
if (!secret) { throw new Error("Set sensorSecret first: send 'Register a sensor' or 'Rotate a sensor's secret'."); }
const body = pm.variables.replaceIn(pm.request.body && pm.request.body.raw ? pm.request.body.raw : "");
pm.request.body.update(body);  // send exactly the bytes we sign
const ts = Math.floor(Date.now() / 1000).toString();
const sig = cryptoJs.HmacSHA256(ts + "." + body, secret).toString(cryptoJs.enc.Hex);
pm.request.headers.upsert({ key: "Ochio-Timestamp", value: ts });
pm.request.headers.upsert({ key: "Ochio-Signature", value: "v1=" + sig });

Run it end to end

With the sandbox running, Postman's Run collection sends every request in order and checks each answer. From a terminal, the Postman CLI does the same, and so does Newman. Start the sandbox with --fresh first.

Terminal
postman collection run ochio-api.postman_collection.json \
  -e ochio-sandbox.postman_environment.json \
  --env-var "apiKey=$OCHIO_API_KEY"

Publish it in Postman

To give partners these docs inside Postman too, import the collection into a team workspace, open its Overview, choose View complete documentation, then Publish docs. Postman's guide, Publishing your docs, walks through it. Leave the environment's key empty before you publish.

OpenAPI

ochio-api.openapi.json describes the same API in OpenAPI 3.1: every path, parameter, request body and answer, with schemas and the examples on these pages. Use it with a code generator, import it into Postman or Insomnia, or load it into your API gateway.

A running Ochio also serves its own description at /openapi.json, and interactive docs at /docs.