# Previews

5 endpoints at `https://api.kosa8.com`, sent with `Authorization: Bearer $KOSA8_API_KEY`. Generated from the API's own [OpenAPI description](https://api.kosa8.com/openapi.json), which a test holds to the router.

## The sandbox's preview URLs (no tokens)[#]

GET`/v1/sandboxes/{id}/previews`scope sandboxes:read

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

Responses

200401403404

```
curl -s -X GET https://api.kosa8.com/v1/sandboxes/$SBX/previews \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Open a port at its own https URL, private (signed link) unless public: true[#]

POST`/v1/sandboxes/{id}/previews`scope sandboxes:write

The server must listen on 0.0.0.0, not 127.0.0.1. Opening a port that is already open answers 200 with a fresh link and applies public, wake and wake_per_hour. A sleeping sandbox's preview answers 503 until it is woken, unless wake is true: then the request wakes it (402 when the organization cannot pay for it, 429 past wake_per_hour).

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`port`requiredinteger

Min 1. Max 65535.

`public`boolean

—

`expires_in_s`integer

How long the link works, in seconds (default 3600) Min 60. Max 604800.

`wake`boolean

Wake the sandbox on a request while it sleeps (default false)

`wake_per_hour`integer

Cap on wakes by preview requests per rolling hour (default 12) Min 1. Max 120.

Responses

201400401403404409410501

```
curl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/previews \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## A new signed link for a private preview[#]

POST`/v1/sandboxes/{id}/previews/{port}/link`scope sandboxes:write

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`port`requiredpath · string

The port in the sandbox, 1-65535

JSON body

`expires_in_s`integer

How long the link works, in seconds (default 3600) Min 60. Max 604800.

Responses

200400401403404501

```
curl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/previews/$PORT/link \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## Move the preview to a new address, ending every earlier link and cookie[#]

POST`/v1/sandboxes/{id}/previews/{port}/rotate`scope sandboxes:write

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`port`requiredpath · string

The port in the sandbox, 1-65535

JSON body

`expires_in_s`integer

How long the link works, in seconds (default 3600) Min 60. Max 604800.

Responses

200400401403404501

```
curl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/previews/$PORT/rotate \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## Close the port's preview[#]

DELETE`/v1/sandboxes/{id}/previews/{port}`scope sandboxes:write

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

`port`requiredpath · string

The port in the sandbox, 1-65535

Responses

200400401403404

```
curl -s -X DELETE https://api.kosa8.com/v1/sandboxes/$SBX/previews/$PORT \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

---
Source: https://docs.kosa8.com/api/previews/
