Redirects send visitors from an old storefront address to a new one: after a product slug change, or when moving a shop from another platform. Each redirect has a `source` (the old path), a `target` (a path or an absolute URL), a match type and an HTTP status. Every change is synced to the storefront.

Reading redirects needs the `storefront:read` scope; creating, updating and deleting them needs `content:write`.

## The Redirect object

| Field | Type | Description |
|-------|------|-------------|
| `id` | `string` | Redirect UUID |
| `storeId` | `string` | Store UUID |
| `source` | `string` | Path to redirect from. Lowercased, without query string and trailing slash for `exact` and `prefix`; kept as sent for `regex` |
| `target` | `string` | A path, or an absolute URL for another domain. Case is kept |
| `matchType` | `"exact"` \| `"prefix"` \| `"regex"` | How `source` is matched |
| `status` | `"301"` \| `"302"` | HTTP status of the redirect |
| `forwardQuery` | `boolean` | Whether the incoming query string is copied onto the target |
| `enabled` | `boolean` | Disabled redirects are kept but not applied |
| `position` | `number` | Evaluation order when several prefix or regex rules match; lower runs first |
| `title` | `string \| null` | Optional note describing the redirect |
| `hits` | `number` | How many times the redirect was used |
| `lastAccessedAt` | `string \| null` | When it was last used |
| `createdAt` | `string` | ISO 8601 timestamp |
| `updatedAt` | `string` | ISO 8601 timestamp |

Write responses can also carry a `warnings` array of strings when a rule could not be made live on the storefront. It is left out when there is nothing to report.

---

## List Redirects

```
GET /api/v1/redirects
```

Returns the store's redirects ordered by `position`, then `source`. Without `limit` or `offset`, every redirect is returned.

### Query Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `limit` | `number` | 1000 | Redirects per page (1-1000). Only applied when `limit` or `offset` is sent |
| `offset` | `number` | 0 | Redirects to skip |

A value that is not a non-negative integer is ignored.

```bash
curl \
  -H "Authorization: Bearer your_api_key" \
  "https://your-store.yns.store/api/v1/redirects?limit=100&offset=0"
```

### Response

```json
{
  "data": [
    {
      "id": "0191abc0-1234-7def-8000-000000000001",
      "storeId": "0191abc0-0000-7def-8000-000000000001",
      "source": "/old-product",
      "target": "/product/new-product",
      "matchType": "exact",
      "status": "301",
      "forwardQuery": true,
      "enabled": true,
      "position": 0,
      "title": null,
      "hits": 12,
      "lastAccessedAt": "2026-11-28T10:00:00.000Z",
      "createdAt": "2026-11-01T09:00:00.000Z",
      "updatedAt": "2026-11-01T09:00:00.000Z"
    }
  ]
}
```

---

## Get Redirect

```
GET /api/v1/redirects/:id
```

Returns one redirect by UUID, as a bare [Redirect object](#the-redirect-object). Returns `404` when the store has no redirect with that id.

---

## Create Redirect

```
POST /api/v1/redirects
```

Creates one redirect. To create many at once, send an array instead: see [Create Many Redirects](#create-many-redirects).

### Request Body

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `source` | `string` | Yes | Path to redirect from, e.g. `/old-url`. A regular expression when `matchType` is `regex` |
| `target` | `string` | Yes | A path, or an absolute URL for another domain. May carry its own query string, and `$1`-`$9` backreferences when `matchType` is `regex` |
| `matchType` | `"exact"` \| `"prefix"` \| `"regex"` | No | `exact` (default): the path must match exactly. `prefix`: the path or anything beneath it matches, and the remaining segments are appended to the target. `regex`: `source` is a regular expression |
| `status` | `"301"` \| `"302"` | No | `301` (default) for a permanent move, `302` when the old URL will come back |
| `forwardQuery` | `boolean` | No | Copy the incoming query string onto the target; params set on the target win (default `true`) |
| `enabled` | `boolean` | No | Default `true` |
| `position` | `number` | No | Integer, at least `0` (default `0`) |
| `title` | `string \| null` | No | Optional note, up to 200 characters |

Unknown fields are rejected.

```bash
curl -X POST \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"source": "/old-product", "target": "/product/new-product"}' \
  https://your-store.yns.store/api/v1/redirects
```

### Response (201)

The created [Redirect object](#the-redirect-object), plus `warnings` when there are any.

### Errors

| Status | When |
|--------|------|
| `400` | Invalid body; `source` and `target` are the same URL; a `regex` source that is empty, longer than 500 characters, has a repeat inside a repeat (like `(a+)+`) or does not compile |
| `409` | The store already has a redirect for that source. Update it with `PATCH`, or send a different source |

---

## Create Many Redirects

```
POST /api/v1/redirects
```

Send an array of 1 to 5,000 redirects, each with the fields of [Create Redirect](#request-body), to write them in one request with a single storefront sync.

- Every row is checked first. If any row is invalid, or the same source appears twice in the batch, nothing is written.
- A source the store already has is updated instead of refused, so the same batch can be sent again.

```bash
curl -X POST \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '[
    {"source": "/126-Wohnwand.html", "target": "/product/wohnwand"},
    {"source": "/148-Holzbett.html", "target": "/product/holzbett", "status": "302"}
  ]' \
  https://your-store.yns.store/api/v1/redirects
```

### Response (200)

`count` is the number of redirects created or updated.

```json
{
  "count": 2
}
```

### Errors

An empty array or one over 5,000 rows returns `400`. Invalid rows return `400` naming each row by its 1-based position (up to 20), for example `row 2: source sent twice`, with this hint:

```json
{
  "error": "… row 2: source sent twice",
  "hint": "Fix these rows and resend the batch; nothing was written."
}
```

Sources are compared after normalising, so `/Old` and `/old/` count as the same source.

---

## Update Redirect

```
PATCH /api/v1/redirects/:id
```

Send any subset of the [Create Redirect](#request-body) fields; omitted fields keep their current value.

```bash
curl -X PATCH \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"status": "302", "enabled": false}' \
  https://your-store.yns.store/api/v1/redirects/0191abc0-1234-7def-8000-000000000001
```

### Response (200)

The updated [Redirect object](#the-redirect-object), plus `warnings` when there are any. Returns `404` when the redirect does not exist, `400` for an invalid rule and `409` when another redirect already owns the new source.

---

## Delete Redirect

```
DELETE /api/v1/redirects/:id
```

Deletes one redirect. Returns `204` with no body, or `404` when the store has no redirect with that id.

```bash
curl -X DELETE \
  -H "Authorization: Bearer your_api_key" \
  https://your-store.yns.store/api/v1/redirects/0191abc0-1234-7def-8000-000000000001
```

---

## Delete Many Redirects

```
DELETE /api/v1/redirects
```

Send a JSON array of 1 to 5,000 redirect UUIDs to delete them in one request with a single storefront sync. An id the store does not have is skipped.

```bash
curl -X DELETE \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '["0191abc0-1234-7def-8000-000000000001", "0191abc0-1234-7def-8000-000000000002"]' \
  https://your-store.yns.store/api/v1/redirects
```

### Response (200)

`count` is the number of redirects actually deleted.

```json
{
  "count": 2
}
```

Anything other than an array of 1 to 5,000 UUIDs (an empty array, an id that is not a UUID, or an object such as `{"ids": [...]}`) returns `400`.