> ## Documentation Index
> Fetch the complete documentation index at: https://developers.onio.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Back up your wishlists

> Write all your wishlists and wishes to a JSON file.

This guide uses Node.js 20 or later. It reads every wishlist you own, then every wish of each list, and writes one JSON file.

> [!TIP]
>
> For a one-time export, you do not need the API. Use **Your Data** in your Onio profile to download
> JSON or CSV.

## 1. Create a token

Create a token in your profile as described in the [Quickstart](https://developers.onio.app/quickstart.md). Store it in `ONIO_TOKEN`.

## 2. Write the script

Save this as `backup.mjs`:

```javascript backup.mjs theme={null}
import { writeFile } from 'node:fs/promises';

const BASE_URL = 'https://web.onio.app/api/v1';
const token = process.env.ONIO_TOKEN;

async function readAll(path) {
  const items = [];
  let cursor = null;

  while (true) {
    const url = new URL(`${BASE_URL}${path}`);
    url.searchParams.set('limit', '100');
    if (cursor) url.searchParams.set('cursor', cursor);

    const response = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
    if (response.status === 429) {
      const seconds = Number(response.headers.get('Retry-After') ?? 60);
      await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
      continue;
    }
    if (!response.ok) throw new Error(`Onio API returned ${response.status} for ${url}`);

    const page = await response.json();
    items.push(...page.data);
    if (!page.nextCursor) return items;
    cursor = page.nextCursor;
  }
}

const wishlists = await readAll('/wishlists');
for (const wishlist of wishlists) {
  wishlist.wishes = await readAll(`/wishlists/${wishlist.id}/wishes`);
}

const fileName = `onio-backup-${new Date().toISOString().slice(0, 10)}.json`;
await writeFile(fileName, JSON.stringify({ wishlists }, null, 2));
console.log(`Saved ${wishlists.length} wishlists to ${fileName}`);
```

## 3. Run it

```bash theme={null}
ONIO_TOKEN="onio_pat_your_token" node backup.mjs
```

The script waits and retries when it reaches the [rate limit](https://developers.onio.app/rate-limits.md).

## What the backup contains

* All wishlists you own, including private and archived ones.
* All wishes of these lists, including private ones.

It does not contain lists of other people, followers, share links, or who is getting a wish.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.