# Sync loads to your spreadsheet or n8n

> Pull every Techvia TMS load into a CSV for Excel or Google Sheets with a short script, or into n8n with the HTTP Request node, staying inside the rate limits.

Source: https://techvia.software/docs/tms/use-cases/sync-loads-to-a-spreadsheet/

**Outcome:** a CSV (or an n8n workflow) with your loads, refreshed whenever you run it, that you can open in Excel or Google Sheets or feed to Power BI.

## Steps

1. **Make a read-only key** in **Settings > API keys** with `loads.read`. Add `billing.read` only if the sheet needs `finalRate`. Store it as `TMS_KEY`.
2. **Read one page.** `GET /api/public/v1/loads` returns up to 50 loads, newest first, as `{ "items": [...], "page", "pageSize", "total", "hasMore" }`. Narrow it with filters such as `status`, `pickupFrom` and `pickupTo` (`YYYY-MM-DD`), or `search`.
3. **Loop until `hasMore` is `false`**, raising `page` by one. Keep the loop under the limit of 60 requests a minute per key.
4. **Write the rows.** Show people `pickupLocal` and `deliveryLocal` (the wall clock at the facility), not the UTC `pickupDate`. Skip loads with `isSample: true` if the sheet should hold only your own.

**Python**

```python

BASE = "https://tms-api.techvia.software/api/public/v1/loads"
headers = {"Authorization": f"Bearer {os.environ['TMS_KEY']}"}
columns = ["loadNumber", "workOrderNumber", "status", "customerName", "origin", "destination", "pickupLocal", "deliveryLocal"]

with open("loads.csv", "w", newline="", encoding="utf-8") as f:
    out = csv.DictWriter(f, fieldnames=columns, extrasaction="ignore")
    out.writeheader()
    page = 1
    while True:
        res = requests.get(BASE, headers=headers, params={"page": page, "pageSize": 50, "pickupFrom": "2026-12-01"})
        res.raise_for_status()
        body = res.json()
        out.writerows(l for l in body["items"] if not l["isSample"])
        if not body["hasMore"]:
            break
        page += 1
```

**JavaScript**

```js

const base = 'https://tms-api.techvia.software/api/public/v1/loads';
const headers = { Authorization: `Bearer ${process.env.TMS_KEY}` };
const columns = ['loadNumber', 'workOrderNumber', 'status', 'customerName', 'origin', 'destination', 'pickupLocal', 'deliveryLocal'];
const cell = (v) => `"${String(v ?? '').replaceAll('"', '""')}"`;

const rows = [columns.join(',')];
for (let page = 1; ; page++) {
  const res = await fetch(`${base}?page=${page}&pageSize=50&pickupFrom=2026-12-01`, { headers });
  if (!res.ok) throw new Error(await res.text());
  const body = await res.json();
  for (const l of body.items.filter((l) => !l.isSample)) rows.push(columns.map((c) => cell(l[c])).join(','));
  if (!body.hasMore) break;
}
writeFileSync('loads.csv', rows.join('\n'));
```

**curl**

```bash
curl -H "Authorization: Bearer $TMS_KEY" \
  "https://tms-api.techvia.software/api/public/v1/loads?page=1&pageSize=50&pickupFrom=2026-12-01"
```

## In n8n

1. Add an **HTTP Request** node: method `GET`, URL `https://tms-api.techvia.software/api/public/v1/loads`.
2. Authentication: **Generic Credential Type > Header Auth**, name `Authorization`, value `Bearer tms_YOUR_KEY`.
3. Under **Options > Pagination**, step the `page` query parameter by one and stop when `hasMore` is `false`. Put a **Schedule Trigger** in front and a **Google Sheets** or **Spreadsheet File** node after it.

## Next steps

- All filters and fields: [Loads guide](/docs/tms/guides/loads/) and [List loads](/docs/tms/reference/loads/list-loads/).
- If a call returns `429`, wait the seconds in the `Retry-After` header: [rate limits and quota](/docs/tms/concepts/rate-limits/).
- Create loads from a sheet instead? Use [Create a load](/docs/tms/reference/loads/create-a-load/) with an `Idempotency-Key` per row.
