> For the complete documentation index, see [llms.txt](https://docs.millimetric.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.millimetric.ai/sdks/curl.md).

# curl & raw HTTP

You don't need an SDK. Every Millimetric endpoint is a plain HTTPS call with a `Bearer` token. Useful for shell scripts, GitHub Actions, cron jobs, server backfills, or anything we don't ship a library for yet.

## Auth

```http
Authorization: Bearer {key}
Content-Type: application/json
```

For `pk_*` keys, also include `Origin:` matching the project's allowlist (`pk_*` from servers will fail without it).

## Ingest one event

```bash
curl -X POST https://api.millimetric.ai/v1/track \
  -H "Authorization: Bearer $SK_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "signup",
    "anonymous_id": "u_abc",
    "user_id": "user_42",
    "properties": { "plan": "free" }
  }'
```

Expected: `202 {"ok":true,"event_id":null}`.

## Ingest a batch

```bash
curl -X POST https://api.millimetric.ai/v1/batch \
  -H "Authorization: Bearer $SK_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      { "event": "$pageview", "anonymous_id": "u_a", "url": "https://yoursite.com/?utm_source=facebook&utm_medium=cpc" },
      { "event": "signup",     "anonymous_id": "u_a", "user_id": "user_1" }
    ]
  }'
```

## Identify

```bash
curl -X POST https://api.millimetric.ai/v1/identify \
  -H "Authorization: Bearer $SK_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "anonymous_id": "u_abc",
    "user_id": "user_42",
    "traits": { "email": "matt@example.com", "plan": "pro" }
  }'
```

## Forget a user

```bash
curl -X POST https://api.millimetric.ai/v1/forget \
  -H "Authorization: Bearer $SK_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "user_id": "user_42" }'
```

## Query — top sources this month

```bash
curl -G "https://api.millimetric.ai/v1/sources" \
  -H "Authorization: Bearer $RK_KEY" \
  --data-urlencode "from=2026-05-01T00:00:00Z" \
  --data-urlencode "to=2026-06-01T00:00:00Z" \
  | jq
```

## Query — daily signups by source

```bash
curl -G "https://api.millimetric.ai/v1/stats" \
  -H "Authorization: Bearer $RK_KEY" \
  --data-urlencode "metric=count" \
  --data-urlencode "event=signup" \
  --data-urlencode "from=2026-05-01T00:00:00Z" \
  --data-urlencode "to=2026-06-01T00:00:00Z" \
  --data-urlencode "group_by=source,medium" \
  --data-urlencode "interval=day"
```

## Browser-side (`pk_*`) — needs `Origin`

```bash
curl -X POST http://localhost:8787/v1/track \
  -H "Authorization: Bearer $PK_KEY" \
  -H "Origin: http://localhost:5173" \
  -H "Content-Type: application/json" \
  -d '{ "event": "$pageview", "anonymous_id": "u_test", "url": "https://yoursite.com/?fbclid=abc" }'
```

If `Origin` is missing or not allowlisted you'll get:

```
403 {"error":"origin_not_allowed","origin":"http://localhost:5173"}
```

## Tips

* **Pipe to `jq`**: `curl … | jq` for legible JSON.
* **Save keys to a .env file**: `export SK_KEY=sk_live_…` and source it once per shell.
* **Use a fish/zsh function** for repeated queries — the URL-encoded query params can get long.
* **Logs from the Worker**: when something goes wrong, `wrangler tail` (or `pnpm dev:api` locally) shows the full traceback. The HTTP response only ever returns a short `error` code.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.millimetric.ai/sdks/curl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
