Before you start

Quickstart: your first API call

What you need. Three things, and one rule.

Make a key that can only read.

Start read-only. A read-only key cannot change anything, so a mistake costs nothing.

  1. Sign in at https://app.terania.ai and open Administration, then API keys (/admin/api-keys).

  2. Choose to make a key. Terania asks you to prove it is you again. This is expected.

  3. Name it, for example "Quickstart read-only" (1 to 80 characters).

  4. Leave customer:read ticked. Tick case:read too if you want to try cases.

  5. Leave "Expires after" at 90 days, or choose 1 to 366.

  6. Create the key and copy it at once. The screen says: "Copy the key now. It will not be shown again, and nobody can recover it for you."

  7. Put it in your shell. Do not paste it into a file you commit.

bash
export TERANIA_KEY='paste-the-key-here'

List two customers.

Send the key as a Bearer header. Keys in the query string are refused.

bash
curl -s -i "https://app.terania.ai/api/v1/customers?limit=2" \
  -H "Authorization: Bearer $TERANIA_KEY"
js
const res = await fetch("https://app.terania.ai/api/v1/customers?limit=2", {
  headers: { Authorization: `Bearer ${process.env.TERANIA_KEY}` },
});
console.log(res.status, res.headers.get("API-Version"));
console.log(JSON.stringify(await res.json(), null, 2));
python
import json, os, urllib.request

req = urllib.request.Request(
    "https://app.terania.ai/api/v1/customers?limit=2",
    headers={"Authorization": "Bearer " + os.environ["TERANIA_KEY"]},
)
with urllib.request.urlopen(req) as res:
    print(res.status, res.headers.get("API-Version"))
    print(json.dumps(json.load(res), indent=2))

The shape of a list.

A list answers with the module's own list. Customers return a customers array and a reach object. The next cursor is in reach.next. When it is null, there are no more rows.

json
{
  "customers": [
    { "id": "<id>", "displayName": "Sample Customer Ltd" }
  ],
  "limit": 2,
  "reach": { "next": "<cursor>" }
}

Send the cursor back.

Pass the last cursor as after. limit is clamped to 1 to 100 and is 50 by default. A garbage or deleted cursor starts at the first page. Lists are not snapshots, so deduplicate by id.

bash
curl -s "https://app.terania.ai/api/v1/customers?limit=2&after=<cursor>" \
  -H "Authorization: Bearer $TERANIA_KEY"

Open a case, once.

Writes need a key with write scopes. Make a second key with case:create, and do not reuse the read-only one. Case, task and mission creates accept an Idempotency-Key header of 1 to 128 characters: send the same key and body again and you get the stored record back, not a second case.

bash
curl -s -i -X POST "https://app.terania.ai/api/v1/cases" \
  -H "Authorization: Bearer $TERANIA_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"subject":"Quickstart test case","purpose":"question"}'

Four things to look for.

  1. The status is 200 for a read and 201 for a first create.

  2. The response carries API-Version: 1.

  3. The response carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset.

  4. In Administration, API keys, the key shows a recent "Last used" time. It updates at most once a minute.

When it does not work.

  1. 401 unauthorized. The key is missing, wrong, revoked, expired, or its maker has left or been suspended. All of these answer the same, on purpose. Check the header is Authorization: Bearer <key> and that the key was not sent as ?key=, ?api_key= or ?token=.

  2. 403 write_forbidden. The key has no write scope for this change, or the person who made it no longer holds it. Make a new key.

  3. 403 forbidden. A collection read the key is not allowed to make.

  4. 404 not_found. The ID does not exist, or belongs to another organisation, or is refused. These look identical.

  5. 400 invalid_request. An unknown field, or a body that is not a JSON object.

  6. 429 rate_limited. Wait for Retry-After seconds. The limit is 100 a minute per key. Every error body has error, code and, when available, requestId. Quote the requestId if you ask us for help.

Go further.