Skip to the page
Docs menu

Docs Start

Quickstart

Run the whole loop of a Timbereye integration now, in test mode, with no phone: create a group, scan sawlogs into it with the simulator, and update your record from the event.

Start here. You will run the three steps of an integration, Create → Scan → Sync, in test mode. A simulator stands in for the worker's phone. At the end your own record for container MSKU1234567 holds its piece count and volume. The quickstart uses sawlogs (What is available).

Get a test key#

Sign up: your test key (a secret key, te_test_sk_…) is on the console's Home from the start, with these three steps. Copy it there or from API keys, any time. For the CLI, timbereye login gets the test key for you: it opens your browser, you click Approve, and there is nothing to paste. A test key is free and works only in test mode, where nothing is billed.

The fastest way: the CLI#

To see the whole loop before you write any code, the CLI runs it in under a minute. Install it (Node 20 or later):

npm
npm install -g timbereye
curl
curl -fsSL https://www.timbereye.com/install.sh | sh

Then run timbereye login (check the code in your browser, click Approve) and timbereye quickstart. It creates a group, scans 12 simulated logs into it, and prints the tally and the group.measured event your server would receive. See the CLI's 60-second start for what it prints. Then do the same from your own code below, in TypeScript or with curl.

Before you start#

Install the TypeScript SDK in your backend with npm install @timbereye/sdk, and set your test key where your code will find it:

Shell
export TIMBEREYE_SECRET_KEY=te_test_sk_...

1. Create#

When your backend creates its record for a container, it creates the Timbereye group:

TypeScript
import Timbereye from "@timbereye/sdk"

const timbereye = new Timbereye() // reads TIMBEREYE_SECRET_KEY
const group = await timbereye.groups.create({
    kind: "container",
    externalRef: "ctr_4821", // your record's id
    name: "MSKU1234567",
    defaults: { species: "PINE_TAEDA", length: { valueM: 5.8 } },
})
curl
curl https://api.timbereye.com/v1/groups \
  -H "Authorization: Bearer $TIMBEREYE_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "kind": "container", "external_ref": "ctr_4821", "name": "MSKU1234567",
        "defaults": { "species": "PINE_TAEDA", "length": { "value_m": 5.8 } } }'
CLI
timbereye groups create --kind container --external-ref ctr_4821 --name MSKU1234567 \
  --species PINE_TAEDA --length 5.8m --json
JSON
{
    "id": "grp_7QxV3m",
    "object": "group",
    "kind": "container",
    "name": "MSKU1234567",
    "external_ref": "ctr_4821"
}

Store id on your container record: it is how step 3 finds the record.

2. Scan#

In production a worker scans the logs with the Timbereye app or your own app; the phone uploads them and the server refines each one. Here the simulator stands in for the phone: it scans 35 synthetic logs, and a second call refines them now instead of in the background:

TypeScript
const scan = await timbereye.testMode.simulateScan({ groupId: "grp_7QxV3m", logs: 35 })
await timbereye.testMode.runRefinements()
curl
curl https://api.timbereye.com/v1/test/scans/simulate \
  -H "Authorization: Bearer $TIMBEREYE_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "group_id": "grp_7QxV3m", "logs": 35 }'

curl -X POST https://api.timbereye.com/v1/test/refinements/run \
  -H "Authorization: Bearer $TIMBEREYE_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
CLI
timbereye simulate scan --group grp_7QxV3m --logs 35 --wait-until refined --json
JSON
{
    "id": "scn_9a2Lk",
    "object": "scan",
    "method": "qr_scale",
    "status": "refined",
    "group_id": "grp_7QxV3m",
    "results": { "count": 35 }
}

Once every log of the scan is refined, the group's tally has settled and group.measured is sent. Simulated logs are marked as such and never billed. More: Test mode.

3. Sync#

When a scan's logs have all been refined, Timbereye sends group.measured to your webhook endpoint with the group's tally. A later scan into the same group, or a correction, sends it again with the next revision; keep the highest. The handler updates your record:

TypeScript
const onEvent = timbereye.webhooks.handler(async (event) => {
    if (event.type === "group.measured") {
        const { externalRef, revision, pieces, volume } = event.data.object
        // Redelivered or late events carry a lower revision: apply only a newer one.
        await db.query(
            "UPDATE containers SET pieces = $1, volume_m3 = $2, tally_revision = $3 WHERE id = $4 AND tally_revision < $3",
            [pieces, volume?.m3, revision, externalRef],
        )
    }
})
app.post("/webhooks/timbereye", express.raw({ type: "application/json" }), onEvent)

The event as it arrives, abbreviated:

JSON
{
    "type": "group.measured",
    "data": {
        "object": {
            "object": "group_tally",
            "group_id": "grp_7QxV3m",
            "external_ref": "ctr_4821",
            "name": "MSKU1234567",
            "revision": 1,
            "reason": "scan_settled",
            "pieces": 35,
            "volume": { "rule": "jas", "m3": 11.113 }
        }
    }
}

Your record afterwards:

idcontainertimbereye_group_idpiecesvolume_m3tally_revision
ctr_4821MSKU1234567grp_7QxV3m3511.1131

Why your volume differs from this example: the simulator draws its own diameters. In any group, m3 also includes the nominal volume of logs that were counted but not measured (stage assigned), which the volume's items count leaves out. No public URL yet? timbereye events tail --json prints the events as they happen. Registering an endpoint and its secret: Stay in sync.

Read the logs#

Every log, with its tag, diameters and photo, stays readable under the group's id. The API calls a log an item.

TypeScript
const page = await timbereye.groups.items.list("grp_7QxV3m")
curl
curl https://api.timbereye.com/v1/groups/grp_7QxV3m/items \
  -H "Authorization: Bearer $TIMBEREYE_SECRET_KEY"
CLI
timbereye groups items list grp_7QxV3m --json
JSON
{
    "object": "list",
    "data": [
        {
            "id": "itm_5Lw2Nc",
            "object": "item",
            "tag": { "payload": "DEMO-0001" },
            "measurement": { "stage": "server_refined", "diameter_short_m": 0.477, "diameter_long_m": 0.492 }
        }
    ],
    "has_more": true,
    "next_cursor": "…"
}

Abbreviated: 25 logs a page by default; for await (const log of timbereye.groups.items.list(...)) walks every page.

Next#