Beta. STARCO Dev works with synthetic data only: do not send real personal or health data. Every feature shows its real status (Available Beta Beta · in development Coming).

Documentation menu

Tutorial 04

Import a week and handle rejections.

Goal: send seven days of synthetic sleep and step observations in one batch, find the line that was rejected, fix it and resend the whole file without ever storing anything twice.

time 15 minlevel intermediateuses observations Beta · layer read Betatabs curl · Python · TypeScript · CLI (the SDK and the command line are not published as packages yet)
  1. 1File
  2. 2Send
  3. 3Rejections
  4. 4Fix
  5. 5Check

STEP 1 Prepare the week#

One observation per line (JSON Lines). The values are synthetic and written by hand. The night of the 14th was not recorded, so it has no line: that is the truth, not an error. Line 8 has a mistake on purpose: its observed_at is missing.

{"kind": "sleep_hours", "value": 7.2, "unit": "h", "observed_at": "2026-11-12T07:00:00Z"}
{"kind": "sleep_hours", "value": 6.8, "unit": "h", "observed_at": "2026-11-13T07:00:00Z"}
{"kind": "sleep_hours", "value": 7.5, "unit": "h", "observed_at": "2026-11-15T07:00:00Z"}
{"kind": "sleep_hours", "value": 7.1, "unit": "h", "observed_at": "2026-11-16T07:00:00Z"}
{"kind": "sleep_hours", "value": 8.0, "unit": "h", "observed_at": "2026-11-17T07:00:00Z"}
{"kind": "sleep_hours", "value": 7.7, "unit": "h", "observed_at": "2026-11-18T07:00:00Z"}
{"kind": "steps", "value": 8120, "unit": "steps", "observed_at": "2026-11-12T21:00:00Z"}
{"kind": "steps", "value": 6450, "unit": "steps"}
{"kind": "steps", "value": 9930, "unit": "steps", "observed_at": "2026-11-14T21:00:00Z"}
{"kind": "steps", "value": 7310, "unit": "steps", "observed_at": "2026-11-15T21:00:00Z"}
{"kind": "steps", "value": 5880, "unit": "steps", "observed_at": "2026-11-16T21:00:00Z"}
{"kind": "steps", "value": 10240, "unit": "steps", "observed_at": "2026-11-17T21:00:00Z"}
{"kind": "steps", "value": 7765, "unit": "steps", "observed_at": "2026-11-18T21:00:00Z"}

STEP 2 Send it as one batch Beta#

The API takes JSON, not JSON Lines: wrap the lines in {"observations": [ … ]}. A batch holds up to 500 lines.

jq -s '{observations: .}' week.jsonl > week.json
curl -X POST "$API/twins/$TWIN/observations" \
  -H "Authorization: Bearer $STARCO_KEY" -H "Content-Type: application/json" -d @week.json
Expected outputillustrative · synthetic
200 { "batch_id": "b5e81f3c-…", "accepted": 12,
      "rejected": [ { "index": 7, "reason": "timestamp_invalid", "field": "observed_at",
                      "expected": "RFC 3339 with offset, e.g. 2026-11-19T07:30:00Z" } ],
      "recomputed_layers": ["wellness"] }

index counts from 0, so index 7 is line 8 of the file. The 12 good lines were stored together and the wellness layer was recomputed before the answer.

STEP 3 Read the rejections#

Each rejected line has one stable reason you can program against. The ones you will meet most:

reasonMeaning
timestamp_invalidobserved_at is missing or not RFC 3339 with an offset.
timestamp_out_of_rangeIn the future (beyond five minutes) or before 2000.
unknown_kindNo such kind in the catalogue.
unit_mismatchNot the kind's unit; expected gives it. Nothing is converted for you.
value_not_a_number · value_not_an_integerMissing value or text, or a decimal for an integer kind.
value_out_of_accepted_boundsOutside the accepted bounds; expected is [min, max].
duplicate_in_batch · duplicate_observationThe same kind and time twice in the batch, or already stored.

The full list, in the order lines are checked, is in Concepts.

STEP 4 Fix and resend the whole file Beta#

Fix line 8 from your own records and send the whole file again. You do not need to pick out the failed lines: an observation with the same kind and time as a stored one is refused as duplicate_observation, never stored twice and never overwritten. The same holds if a network error leaves you unsure whether a batch arrived.

lines[7]["observed_at"] = "2026-11-13T21:00:00Z"   # the time we left out, from our own records
r2 = requests.post(f"{API}/twins/{twin_id}/observations", headers=H, json={"observations": lines})
res = r2.json()
print(r2.status_code, res["accepted"], "accepted;", {x["reason"] for x in res["rejected"]})
Expected outputillustrative · synthetic
200 1 accepted; {'duplicate_observation'}
Never guessOnly fix a line when you know the right value from your own source. If you do not know when the steps were counted, leave the line out: the day will have no observation, which is the truth.

STEP 5 Check the week Beta#

curl -s "$API/twins/$TWIN/layers/wellness" -H "Authorization: Bearer $STARCO_KEY" \
  | jq '[.kinds[] | select(.count > 0) | {(.kind): .count}] | add'
Expected outputillustrative · synthetic
{ "steps": 7, "sleep_hours": 6, "hydration_glasses": 3 }

The same week as a picture, line by line: what was stored, the line that had to be fixed, and the night that has no observation.

Seven concentric rings, one per day from 2026-11-12 to 2026-11-18, each a 24-hour dial in UTC. On a ring, an arc is that night's sleep_hours: its length is the value and it ends at the line's observed_at. A dot is that day's steps, at its observed_at, larger for more steps. The ring of 2026-11-14 has no arc: that night has no line, so it is null. Line 8, the steps without an observed_at, cannot be placed on a ring: it waits outside, rejected as timestamp_invalid, until it is fixed and resent, and then it lands on 2026-11-13. First send: 12 accepted, 1 rejected. Resend: 1 accepted, 12 refused as duplicate_observation. Stored in the end: sleep_hours 6, steps 7.

The week, one ring per day. Arc: sleep_hours, as long as its value and ending at its observed_at (the API stores a value and a time, not a bedtime). Dot: steps at its observed_at. Dashed ring: no line for that night, so null, never zero. These are the 13 lines of week.jsonl from step 1.

Synthetic week · the lines of this tutorial

Experimental Seven days with a value is also the least an illustrative scenario needs: steps has them, so GET /v1/twins/{twin}/scenarios/wellness.steps?declared_change=500&to=2026-11-18 answers a baseline and a band; sleep_hours has six nights, so the same question answers null with the reason not_enough_days.

What just happened

Thirteen lines went through the validator one by one. Twelve were stored and triggered a recompute; one bounced with a precise reason. You fixed it from your own records and resent the whole file: the twelve already stored were refused as duplicates and only the fixed line was added. hydration_glasses has the three days from tutorial 03; the night of the 14th has no sleep observation, and every kind never sent keeps count 0 and null values.

week.jsonl validatorline by line twin12 + 1 stored missing observed_at → fix → resend

Next steps#