# Sites

> Create, change, publish and delete sites. 7 endpoints in the Unvop API.

Create, change, publish and delete sites.

## The site schema

`GET /v1/schema`

No key needed.

What a SiteSpec may contain for a theme: the theme’s tokens and forms, every block type with its fields, and the SiteSpec JSON Schema. Use it to write a whole site for POST /sites, or valid blocks for pages. No key needed.

### Query parameters

- `theme` (string): A theme id. Default: the base theme.

### Response 200

- `version` (string, required)
- `blocks` (array, required)
- `siteSpec` (any, required)

### Errors

- `422`: The body is invalid; details say which values.

### Example

```sh
curl https://api.unvop.com/v1/schema
```

## Create a site

`POST /v1/sites`

Scope: `sites:write`.

Create a site from a SiteSpec you wrote, or from the base template with just a name. To have Unvop research, design and write the whole site from a description, start a build with POST /builds instead. Add ?dryRun=1 to validate without creating anything.

### Headers

- `Idempotency-Key` (string): Send the same key to repeat this request safely; the first answer is replayed for 24 hours. (up to 200 characters)

### Request body (JSON)

- `spec` (object): A whole SiteSpec (see GET /schema). Leave it out to start from the base template.
- `name` (string): (at least 1 characters; up to 120 characters)
- `hostname` (string): A web address for the site. Without one, a free subdomain is assigned when the platform has one.
- `owner` (object): Invite this person as the owner. They get a link to set their password.
  - `email` (string, required): (email)
  - `name` (string): (up to 120 characters)
- `publish` (boolean): (default true)

### Response 201

- `site` (object, required, nullable): A website.
  - `id` (string, required)
  - `name` (string, required)
  - `hostnames` (array of strings, required): The web addresses the site answers at.
  - `theme` (string, required)
  - `settings` (object, required): Navigation, footer, organization, SEO, tokens, design and more.
  - `createdAt` (string, required): An ISO 8601 timestamp.
- `urls` (object, required)
  - `site` (string, required, nullable)
  - `admin` (string, required)
  - `setup` (string, required, nullable)
  - `preview` (string, required, nullable)
- `warnings` (array of objects, required)
  - `path` (string, required)
  - `message` (string, required)
- `dryRun` (boolean, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `409`: It conflicts with the current state.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Harbour Bakery",
    "owner": {
      "email": "owner@example.com",
      "name": "Sam"
    }
  }'
```

## List sites

`GET /v1/sites`

Scope: `content:read`.

The sites this key can reach, newest first. A site key sees its one site; an account key or OAuth grant sees the account’s sites it was given.

### Query parameters

- `limit` (integer): How many to return (default 50). (min 1; max 200)
- `cursor` (string): The cursor from the previous page.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `name` (string, required)
  - `hostnames` (array of strings, required): The web addresses the site answers at.
  - `theme` (string, required)
  - `settings` (object, required): Navigation, footer, organization, SEO, tokens, design and more.
  - `createdAt` (string, required): An ISO 8601 timestamp.
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Get a site

`GET /v1/sites/{siteId}`

Scope: `content:read`.

One site with its settings.

### Path parameters

- `siteId` (string, required): The site’s id.

### Response 200

- `id` (string, required)
- `name` (string, required)
- `hostnames` (array of strings, required): The web addresses the site answers at.
- `theme` (string, required)
- `settings` (object, required): Navigation, footer, organization, SEO, tokens, design and more.
- `createdAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Update a site

`PATCH /v1/sites/{siteId}`

Scope: `content:write`.

Rename the site, change its web addresses, set brand tokens, the logo and tagline, or replace parts of its settings. Only the fields you send change. Brand tokens, the logo, theme, nav and footer save as a site-wide draft, as in the dashboard: the live site keeps its current look until you publish (POST /sites/{siteId}/publish, or publishing any page). The response shows the settings as they will look once published.

### Path parameters

- `siteId` (string, required): The site’s id.

### Request body (JSON)

- `name` (string): (at least 1 characters; up to 120 characters)
- `hostnames` (array of strings): (up to 10 items)
- `brand` (object): Brand tokens (theme colours and fonts), the logo and the tagline.
  - `tokens` (map of string)
  - `logoUrl` (string): (up to 2,000 characters)
  - `tagline` (string): (up to 200 characters)
- `settings` (object): Replace these settings: tagline, nav, footer, organization, seo, theme, crm. nav, footer and theme save as a draft until you publish.

### Response 200

- `id` (string, required)
- `name` (string, required)
- `hostnames` (array of strings, required): The web addresses the site answers at.
- `theme` (string, required)
- `settings` (object, required): Navigation, footer, organization, SEO, tokens, design and more.
- `createdAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `409`: It conflicts with the current state.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X PATCH https://api.unvop.com/v1/sites/site_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Harbour Bakery",
    "hostnames": [
      "harbour-bakery.unvop.dev"
    ]
  }'
```

## Delete a site

`DELETE /v1/sites/{siteId}`

Scope: `sites:write`.

Delete a site. Add ?confirm=<siteId> to show you mean it. By default the site is hidden and its addresses released; add &hard=1 to remove it and all its data permanently. Needs a platform key.

### Path parameters

- `siteId` (string, required): The site’s id.

### Query parameters

- `confirm` (string, required): The site id again.
- `hard` (string): 1 to delete permanently. One of `1`.

### Response 200

- `ok` (true, required)
- `deleted` (string, required): One of `soft`, `hard`.

### Errors

- `400`: The request is malformed.
- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `410`: Gone.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X DELETE https://api.unvop.com/v1/sites/site_123?confirm=site_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Publish every page

`POST /v1/sites/{siteId}/publish`

Scope: `content:write`.

Publish the draft of every page at once, and the site-wide draft (site style, logo, menu and footer changes) with them. settings lists the parts of the site-wide draft that went live (empty when there was none). To publish one page, use POST /sites/{siteId}/pages/{page}/publish, which also publishes the site-wide draft.

### Path parameters

- `siteId` (string, required): The site’s id.

### Response 200

- `ok` (true, required)
- `published` (integer, required)
- `settings` (array of strings, required): One of `style`, `logo`, `menu`, `footer`.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X POST https://api.unvop.com/v1/sites/site_123/publish \
  -H "Authorization: Bearer $UNVOP_KEY"
```
