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

Example 08

Import a batch, line by line.

Send a batch of observations from a file. Each line is judged on its own: the good ones are stored, the bad ones come back with the index of the line and a stable reason, and sending the same batch again stores nothing twice.

time 4 minuses observations · validation per line · idempotent import Betadata synthetic
Beta.The API this program calls is in beta and works with synthetic data only. The program is complete: with a project key in STARCO_KEY it runs as it is. The TypeScript and CLI tabs use the SDK and the command line, which are not published yet.

The idea#

A batch holds up to 500 observations. The answer is 200 when at least one line was accepted and 422 when none was; either way rejected lists each refused line with its index and reason. An observation identical to one already stored is rejected as duplicate_observation, so an import can be repeated safely.

The whole program#

export API="https://api.starco.dev/v1"
AUTH="Authorization: Bearer $STARCO_KEY"
JSON="Content-Type: application/json"
TWIN=$(curl -s -X POST "$API/twins" -H "$AUTH" -H "$JSON" \
  -d '{"template": "daily_movement", "layers": ["wellness"], "label": "import"}' | jq -r .twin.id)
cat > batch.json <<'EOF'
{"observations": [
  {"kind": "steps", "value": 7420, "unit": "steps", "observed_at": "2026-11-14T21:00:00Z"},
  {"kind": "steps", "value": 9130, "unit": "steps", "observed_at": "2026-11-15T21:00:00Z"},
  {"kind": "steps", "value": -5, "unit": "steps", "observed_at": "2026-11-16T21:00:00Z"},
  {"kind": "sleep_hours", "value": 450, "unit": "min", "observed_at": "2026-11-16T07:00:00Z"},
  {"kind": "sleep_hours", "value": 7.5, "unit": "h", "observed_at": "2026-11-16T07:00:00Z"}]}
EOF
curl -s -X POST "$API/twins/$TWIN/observations" -H "$AUTH" -H "$JSON" -d @batch.json \
  | jq -r '"accepted \(.accepted)", (.rejected[] | "line \(.index): \(.reason)")'
curl -s -X POST "$API/twins/$TWIN/observations" -H "$AUTH" -H "$JSON" -d @batch.json | jq -r '"again: accepted \(.accepted), rejected \(.rejected | length)"'
Output of the curl tabillustrative · synthetic
accepted 3
line 2: value_out_of_accepted_bounds
line 3: unit_mismatch
again: accepted 0, rejected 5

The other tabs print the same facts in their own format. Ids, hashes and counts depend on your project.

What just happened

Three lines were stored. The negative steps and the sleep sent in minutes were refused with a reason each, and nothing of them was kept. The second send stored nothing: the three good lines were already there.

Go further#