# Quickstart

> Make your first request to the Asense API and read a day of tilt data from a sensor.

The Asense API is a single HTTPS endpoint. You send a `GET` request with the table you want, the device ID and a time window, and the API returns the readings as JSON. This page walks through one request from start to finish.

## 1. Get an API key

Every request carries an API key in the `x-api-key` header. Keys are issued by Semitrónica for the devices on your account. If you don't have one yet, [ask us for a key](https://asense.semitronica.pt/contact/).

Keep the key out of source code and shared notebooks. Read it from an environment variable instead:

```bash
export ASENSE_API_KEY="paste-your-key-here"
```

## 2. Pick a device and a time window

Each sensor has an ID made of `ASENSE` and eight digits, for example `ASENSE00000005`. You will find the IDs of your devices in the Asense dashboard.

Times are Unix timestamps in milliseconds, in UTC. The window below covers 1 December 2025, from 00:00 to 24:00 UTC:

| Parameter | Value | Meaning |
| --- | --- | --- |
| `start_time` | `1764547200000` | 2025-12-01T00:00:00Z |
| `end_time` | `1764633600000` | 2025-12-02T00:00:00Z |

## 3. Make the request

The `data` table holds the summary records a sensor sends, including its tilt angles. This request asks for one day of them:

```bash
curl -s "https://api.semitronica.pt/asense/v2/?table_name=data&id=ASENSE00000005&start_time=1764547200000&end_time=1764633600000" \
  -H "x-api-key: $ASENSE_API_KEY"
```

The response is a JSON object with a `data` list. Each item is one record, with its time in two forms: `time` in milliseconds and `datetime` as an ISO 8601 string. This is the shape of one item, shortened, with illustrative values:

```json
{
  "data": [
    {
      "id": "ASENSE00000005",
      "time": 1764550862370,
      "datetime": "2025-12-01T01:01:02.370000Z",
      "theta": 0.52,
      "phi": 89.4,
      "tamb": 14.2,
      "aavgx": 0.0091,
      "aavgy": -0.0012,
      "aavgz": 0.9998
    }
  ]
}
```

The fields are described in [data: summaries and tilt](https://asense.semitronica.pt/docs/data-model/data/).

## 4. Read every page

A response holds at most `limit` records (256 by default). When there is more data in the window, the response also has a `next_timestamp` field. Send the same request again with `start_time` set to that value, and stop when `next_timestamp` is missing. [Pagination](https://asense.semitronica.pt/docs/api/pagination/) explains this in full.

### Python

```python
import os
import requests

URL = "https://api.semitronica.pt/asense/v2/"
HEADERS = {"x-api-key": os.environ["ASENSE_API_KEY"]}

def fetch(table, device, start, end, **params):
    """Yield every item in the window, following next_timestamp."""
    while True:
        query = {"table_name": table, "id": device, "start_time": start, "end_time": end, **params}
        body = requests.get(URL, headers=HEADERS, params=query, timeout=30).json()
        yield from body.get("data", [])
        if "next_timestamp" not in body:
            break
        start = body["next_timestamp"]

rows = list(fetch("data", "ASENSE00000005", 1764547200000, 1764633600000))
for row in rows:
    print(row["datetime"], row["theta"], row["phi"])
```

### JavaScript

```js
const URL = "https://api.semitronica.pt/asense/v2/";

async function* fetchAll(table, id, start, end, extra = {}) {
  while (true) {
    const query = new URLSearchParams({ table_name: table, id, start_time: start, end_time: end, ...extra });
    const res = await fetch(`${URL}?${query}`, { headers: { "x-api-key": process.env.ASENSE_API_KEY } });
    const body = await res.json();
    yield* body.data ?? [];
    if (body.next_timestamp === undefined) return;
    start = body.next_timestamp;
  }
}

for await (const row of fetchAll("data", "ASENSE00000005", 1764547200000, 1764633600000)) {
  console.log(row.datetime, row.theta, row.phi);
}
```

## Next steps

- Read raw vibration from the [acc table](https://asense.semitronica.pt/docs/data-model/acc/), and choose a JSON layout with [output formats](https://asense.semitronica.pt/docs/api/output-formats/).
- Get the newest record first with `ascending=false`, described in [requests and parameters](https://asense.semitronica.pt/docs/api/).
- Learn how sample times are worked out in [timing and accuracy](https://asense.semitronica.pt/docs/timing-and-accuracy/).

Source page: https://asense.semitronica.pt/docs/quickstart/
