# Add a setup script

`POST https://console.advinservers.com/api/v1/client/user-scripts`

### Overview

Adds a setup script for future server reinstalls. The script runs on the first boot after a reinstall that selects it. Existing servers are not changed.

Send `type` as `cloud-config` to merge settings with the operating system image's configuration, or `bash` to run a shell script. Send a unique account-wide `name` of up to 64 characters and `content` of up to 1 MiB.

### Permissions

Requires the `script.update` (Manage setup scripts) permission for the selected team. Resources outside that team return 404.

## Authorization

Send `Authorization: Bearer <token>` with the request. Your API key, sent as a bearer token. Create one in the control panel under API Keys, give it only the permissions the integration needs, and copy it when it is created. It cannot be shown again. Each key is restricted to one owned team. The key determines the team for every request.

## Body

Sent as `application/json`.

- `name` (string, required): A name unique across the account, 1 to 64 characters, without control characters.
- `type` (string, required): Use cloud-config for configuration settings or bash for a shell script. One of: `cloud-config`, `bash`.
- `content` (string, required): The complete script, up to 1 MiB.

## Response 200

The record, as a JSON object. There is no envelope.

- `id` (string, required): The uuid. A script's autoincrement id never leaves the server.
- `uuid_short` (string, required): The value of `uuid_short`.
- `name` (string, required): The name shown to customers.
- `type` (string, required): The type of operation or resource. One of: `cloud-config`, `bash`.
- `content` (string, required): The complete script content, which may contain credentials. Stored encrypted and readable by its owner.
- `owner` (object | null, required): The value of `owner`.
  - `name` (string, required): The name shown to customers.
  - `email` (string, required): The email address.
- `created_at` (string | null, required): The date and time for created at, in UTC.
- `updated_at` (string | null, required): The date and time for updated at, in UTC.

```json
{
  "id": "8edb21bc-9aee-4bd9-8a02-17043fa82a87",
  "uuid_short": "Uuid short",
  "name": "HEV telemetry agent",
  "type": "cloud-config",
  "content": "#cloud-config\npackage_update: true\npackages:\n  - nginx\n  - prometheus-node-exporter\nwrite_files:\n  - path: /etc/hev/telemetry.env\n    content: |\n      SECTOR=C\n      LAB=anomalous-materials\nruncmd:\n  - systemctl enable --now nginx prometheus-node-exporter\n",
  "owner": {
    "name": "Gordon Freeman",
    "email": "gordon.freeman@blackmesa.example.com"
  },
  "created_at": "2026-03-02T18:58:40+00:00",
  "updated_at": "2026-06-19T10:12:05+00:00"
}
```

## Errors

- `401`: The key was missing, malformed, revoked, or belongs to an account that no longer exists.
- `403`: Access denied. Check the key's team, permissions and allowed IP addresses. Some actions, such as managing API keys, require a browser session. The response message explains the reason.
- `422`: A field is missing or invalid, or the resource cannot accept this change in its current state. Check `message` for details. Field validation also includes an `errors` object keyed by field name.
- `429`: Too many requests. The `Retry-After` header says how many seconds to wait. Limits are per account, so several keys on one account share them.

## Example request

```bash
curl --request POST \
  --url 'https://console.advinservers.com/api/v1/client/user-scripts' \
  --header 'Authorization: Bearer <token>' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "HEV telemetry agent",
  "type": "cloud-config",
  "content": "#cloud-config\npackage_update: true\npackages:\n  - nginx\n  - prometheus-node-exporter\nwrite_files:\n  - path: /etc/hev/telemetry.env\n    content: |\n      SECTOR=C\n      LAB=anomalous-materials\nruncmd:\n  - systemctl enable --now nginx prometheus-node-exporter\n"
}'
```
