# Requests and parameters

> The Asense REST API v2 has one endpoint. Query parameters choose the table, the device, the time window and the shape of the response.

## Endpoint

```
GET https://api.semitronica.pt/asense/v2/
```

All parameters go in the query string. The API answers with JSON and allows calls from any web origin, so you can also call it from a browser page. The machine-readable description of this API is the [OpenAPI 3.1 file](https://asense.semitronica.pt/docs/openapi/asense-v2.yaml).

## Authentication

Send your API key in the `x-api-key` header on every request. Requests without a valid key are refused before they reach the data.

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

## Required parameters

| Name | Type | Description |
| --- | --- | --- |
| `table_name` | string | The table to read: `acc`, `gyr`, `ain`, `fft`, `data`, `env` or `connected`. See [the data model](https://asense.semitronica.pt/docs/data-model/). |
| `id` | string | Device ID: `ASENSE` followed by eight digits, for example `ASENSE00000005`. |
| `start_time` | integer | Start of the window, as a Unix timestamp in milliseconds (UTC). Records at exactly this time are included. |
| `end_time` | integer | End of the window, in the same units. Records at exactly this time are included. |

## Paging and order

| Name | Default | Description |
| --- | --- | --- |
| `limit` | `256` | The most stored records one response reads. For `acc`, `gyr` and `ain` a stored record is one packet of samples, so one page can hold many samples. A value that is not a whole number falls back to 256. |
| `ascending` | `true` | Sort by time, oldest first. Set `false` to get the newest records first. This works on `data`, `env` and `connected` only; other tables return 400. |

When more records are left in the window, the response carries `next_timestamp`. [Pagination](https://asense.semitronica.pt/docs/api/pagination/) shows how to use it in both directions.

## Response shape

| Name | Default | Description |
| --- | --- | --- |
| `merge` | `true` | Joins the stored packets into longer series. On `acc`, `gyr` and `ain` the whole page becomes one item. On `fft` the three axes of each UTC hour become one item with `fft_x`, `fft_y` and `fft_z`. On `data` and `env` records are never joined. Any value other than `false` counts as `true`. |
| `output_format` | `map` | Layout of every time or frequency series: `map`, `tuple_array`, `dict_array`, `combined_tuple` or `combined_dict`. An unknown value falls back to `map`. See [output formats](https://asense.semitronica.pt/docs/api/output-formats/). |
| `timestamps_only` | `false` | On `data` and `env`, returns only the list of record times in the window, with a count, and no readings. This list is never paged and ignores `limit`. |

With `merge=true`, the fields `seq`, `odr` and `scale` are removed from every item, including `data` items. Set `merge=false` to keep them.

## Timing corrections

These parameters apply to the high-rate tables `acc`, `gyr` and `ain`. The defaults give the best sample times, and most users never change them. [Timing and accuracy](https://asense.semitronica.pt/docs/timing-and-accuracy/) explains what each one does.

| Name | Default | Description |
| --- | --- | --- |
| `auto_odr` | `true` | Spaces the samples of each packet by the measured time since the previous packet, instead of the nominal output data rate. Only the value `true` turns it on. |
| `enable_correction` | depends on the device | Repairs single packets whose timestamp is out of step with its neighbours. It is on by default only for devices that need it. |
| `sync_acc_gyr` | same as `enable_correction` | On `gyr`, aligns each gyroscope packet to the accelerometer packet recorded up to 200 ms before it. |
| `load_prior_elements` | `true` when any correction above is on | Reads up to 3 seconds before `start_time` so the first packet of the window can be corrected too. Those extra packets are dropped before the response is sent. |

## Booleans and numbers

Booleans are the strings `true` and `false`. Times are whole milliseconds. Every time in a response is UTC: `time` in milliseconds, and `datetime` as an ISO 8601 string ending in `Z`.

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