# Tools

> Small internal apps over the site’s data. 7 endpoints in the Unvop API.

Small internal apps over the site’s data.

## List tool templates

`GET /v1/sites/{siteId}/tool-templates`

Scope: `tools:read`.

Ready-made tools (a bookings board, an orders table…) to start from.

### Path parameters

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

### Response 200

- `items` (array, 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).
- `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/tool-templates \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List tools

`GET /v1/sites/{siteId}/tools`

Scope: `tools:read`.

The tools you may open: small internal apps (tables, forms, charts) over the site’s collections, contacts and connections.

### Path parameters

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

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `name` (string, required)
  - `description` (string)
  - `icon` (string)
  - `access` (string): One of `owner`, `admin`, `editor`.
  - `spec` (any, required)
- `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).
- `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/tools \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Create a tool

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

Scope: `tools:write`.

Create a tool, blank or from a template (picks fill the template’s choices, such as which collection it shows). Owners and admins only.

### Path parameters

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

### 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)

- `name` (string): (up to 80 characters)
- `templateId` (string)
- `picks` (map of string)
- `description` (string): (up to 280 characters)
- `icon` (string): (up to 40 characters)

### Response 201

- `id` (string, required)
- `name` (string, required)
- `description` (string)
- `icon` (string)
- `access` (string): One of `owner`, `admin`, `editor`.
- `spec` (any, 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).
- `404`: Not found, or not reachable with this key.
- `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/site_123/tools \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Ana",
    "templateId": "template_123"
  }'
```

## Get a tool

`GET /v1/sites/{siteId}/tools/{toolId}`

Scope: `tools:read`.

One tool with its spec: components, queries and layout.

### Path parameters

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

### Response 200

- `id` (string, required)
- `name` (string, required)
- `description` (string)
- `icon` (string)
- `access` (string): One of `owner`, `admin`, `editor`.
- `spec` (any, 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).
- `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/tools/tool_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Change a tool

`PATCH /v1/sites/{siteId}/tools/{toolId}`

Scope: `tools:write`.

Change a tool’s name, icon, description, spec, who may use it (access) or whether it is pinned. Owners and admins only.

### Path parameters

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

### Request body (JSON)

- `name` (string): (up to 80 characters)
- `icon` (string): (up to 40 characters)
- `description` (string): (up to 280 characters)
- `spec` (any)
- `access` (string): One of `owner`, `admin`, `editor`.
- `pinned` (boolean)

### Response 200

- `id` (string, required)
- `name` (string, required)
- `description` (string)
- `icon` (string)
- `access` (string): One of `owner`, `admin`, `editor`.
- `spec` (any, 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).
- `404`: Not found, or not reachable with this key.
- `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/tools/tool_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Ana",
    "icon": "calendar-check"
  }'
```

## Delete a tool

`DELETE /v1/sites/{siteId}/tools/{toolId}`

Scope: `tools:write`.

Delete a tool. Its data stays where it is. Owners and admins only.

### Path parameters

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

### Response 200

- `ok` (true, 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).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

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

## Run a tool query

`POST /v1/sites/{siteId}/tools/{toolId}/queries/{queryId}/run`

Scope: `tools:write`.

Run one of a tool’s queries with the component values it reads (scope), and get its rows or result.

### Path parameters

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

### Request body (JSON)

- `scope` (object): Component state the query reads, like a filter’s value.

### Response 200

- `rows` (array)

### 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.
- `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/site_123/tools/tool_123/queries/bookings/run \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "scope": {}
  }'
```
