SDKs and code samples
Call the network with curl, Java or JavaScript, or use the TypeScript, Python and Java SDKs.
The samples use synthetic data and a sandbox origin in $OHN. Replace the placeholders in angle brackets.
curl
# 1. A token for your registered application (client credentials, JSON body)
TOKEN=$(curl -s -X POST "$OHN/api/ohn/v1/oauth/token" \
-H 'content-type: application/json' -H "Idempotency-Key: $(uuidgen)" \
-d '{"grant_type":"client_credentials","client_id":"<client_id>","client_secret":"<client_secret>","scope":"<scopes>"}' \
| jq -r .access_token)
# 2. A module token for the facility registry (OHN-05)
MODULE=$(curl -s -X POST "$OHN/api/ohn/v1/platform/tokens" \
-H "authorization: Bearer $TOKEN" -H 'content-type: application/json' -H "Idempotency-Key: $(uuidgen)" \
-d '{"module":"ohn-05"}' | jq -r .access_token)
# 3. Read: list facilities
curl -s "$OHN/api/ohn/v1/facilities" -H "authorization: Bearer $MODULE"
Step 2 currently works for a signed-in developer session; for machine sessions it answers no_partner_account until partner module access is released (see Authentication).
JavaScript (Node.js 18+, no dependencies)
const OHN = process.env.OHN;
async function call(path, { method = 'GET', token, body, key } = {}) {
const headers = { accept: 'application/json' };
if (token) headers.authorization = `Bearer ${token}`;
if (body) headers['content-type'] = 'application/json';
if (method !== 'GET') headers['idempotency-key'] = key ?? crypto.randomUUID(); // reuse the same key on retry
for (let attempt = 0; ; attempt++) {
const res = await fetch(OHN + path, { method, headers, body: body && JSON.stringify(body) });
if ((res.status === 429 || res.status === 503) && attempt < 3) {
const wait = Number(res.headers.get('retry-after')) * 1000 || Math.min(8000, 250 * 2 ** attempt) * (0.5 + Math.random());
await new Promise((r) => setTimeout(r, wait));
continue;
}
const data = res.status === 204 ? null : await res.json();
if (!res.ok) throw Object.assign(new Error(data?.title ?? res.statusText), { status: res.status, problem: data });
return data;
}
}
const { access_token } = await call('/api/ohn/v1/oauth/token', {
method: 'POST',
body: { grant_type: 'client_credentials', client_id: process.env.OHN_CLIENT_ID, client_secret: process.env.OHN_CLIENT_SECRET, scope: '<scopes>' },
});
Java (17+, standard library)
import java.net.URI;
import java.net.http.*;
import java.util.UUID;
HttpClient http = HttpClient.newHttpClient();
String ohn = System.getenv("OHN");
HttpRequest token = HttpRequest.newBuilder(URI.create(ohn + "/api/ohn/v1/oauth/token"))
.header("content-type", "application/json")
.header("Idempotency-Key", UUID.randomUUID().toString())
.POST(HttpRequest.BodyPublishers.ofString("""
{"grant_type":"client_credentials","client_id":"%s","client_secret":"%s","scope":"%s"}
""".formatted(System.getenv("OHN_CLIENT_ID"), System.getenv("OHN_CLIENT_SECRET"), "<scopes>")))
.build();
HttpResponse<String> res = http.send(token, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() != 200) throw new IllegalStateException("token: " + res.statusCode() + " " + res.body());
// Parse access_token with your JSON library (Jackson, Gson, ...).
SDKs
Three SDKs with the same surface live in the repository. They are not published to public package registries yet; build them from source.
| Language | Folder | Package |
|---|---|---|
| TypeScript (ESM) | sdk/typescript | @ohn/sdk |
| Python 3.9+ | sdk/python | ohn-sdk (ohn_sdk) |
| Java 17 | sdk/java | org.ohn:ohn-sdk (Maven) |
All three:
- get machine tokens (
ClientCredentials) and module tokens (GatewayTokens); - send an idempotency key on every write and reuse it on retry;
- retry only
429and503(3 times, honouringRetry-After, back-off 250 ms to 8 s) and retry network failures only for reads; - map errors to typed exceptions (
ConsentRequired,AuthenticationError,PolicyDenied,DependencyUnavailable,ValidationError,NotFound,ConflictError,RateLimited); - verify webhooks (
verifyWebhook/verify_webhook/Webhooks.verify) and help deduplicate (SeenEvents).
import { ClientCredentials, GatewayTokens, OhnClient } from '@ohn/sdk';
const machine = new ClientCredentials({ baseUrl, clientId, clientSecret, scope: 'record.read' });
const ohn = new OhnClient({ baseUrl, tokens: new GatewayTokens({ baseUrl, session: machine }) });
var session = new Auth.ClientCredentials(baseUrl, clientId, secret, "orders.read orders.write");
OhnClient ohn = OhnClient.gateway(baseUrl, session, null);
The SDKs’ route tables are checked against the OpenAPI contracts, so an SDK cannot drift from the API reference unnoticed.