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.
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)"'import os, requests
API = "https://api.starco.dev/v1"
H = {"Authorization": f"Bearer {os.environ['STARCO_KEY']}"}
twin = requests.post(f"{API}/twins", headers=H, json={
"template": "daily_movement", "layers": ["wellness"], "label": "import"}).json()["twin"]["id"]
batch = [
{"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"}]
r = requests.post(f"{API}/twins/{twin}/observations", headers=H, json={"observations": batch}).json()
print("accepted", r["accepted"])
for line in r["rejected"]:
print(f"line {line['index']}: {line['reason']}", "←", batch[line["index"]]["value"], batch[line["index"]]["unit"])
again = requests.post(f"{API}/twins/{twin}/observations", headers=H, json={"observations": batch}).json() # 422: nothing new
print("again: accepted", again["accepted"], "rejected", len(again["rejected"]))import { Client } from '@starco/sdk';
const c = new Client({ baseUrl: "https://api.starco.dev/v1", apiKey: process.env.STARCO_KEY });
const twin = (await c.twins.create({ template: "daily_movement", layers: ["wellness"], label: "import" })).id;
const batch = [
{ 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" }];
const r = await c.observations.send(twin, batch); // returns the result also when every line is refused
console.log("accepted", r.accepted);
for (const line of r.rejected) console.log(`line ${line.index}: ${line.reason}`, "←", batch[line.index].value, batch[line.index].unit);
const again = await c.observations.send(twin, batch);
console.log("again: accepted", again.accepted, "rejected", again.rejected.length);export STARCO_BASE_URL="https://api.starco.dev/v1" STARCO_API_KEY="$STARCO_KEY"
TWIN=$(starco --json twins create --template daily_movement --layers wellness --label import | jq -r .id)
cat > batch.json <<'EOF'
[{"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
starco obs send $TWIN batch.json
starco obs send $TWIN batch.json || echo "again: nothing new was stored"accepted 3
line 2: value_out_of_accepted_bounds
line 3: unit_mismatch
again: accepted 0, rejected 5The 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.