> For the complete documentation index, see [llms.txt](https://docs.vagon.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vagon.io/teams/reference/preloaded-scripts.md).

# Preloaded Scripts

## List Scripts

> Returns every script in the organization's \*\*preloaded-scripts pool\*\*, newest first.\
> \
> Preloaded scripts are switched on per organization from the backoffice; while off, every route\
> under this tag answers \`4236\`.\
> \
> A preloaded script is created once in the pool and then \*\*linked\*\* to any number of the\
> organization's machines (\`POST /machines/{id}/scripts/link\`), each link saying whether the\
> script runs at the start of \*\*every session\*\* or \*\*once\*\*. A machine runs its linked scripts\
> when its next session starts, after its preloaded files have been copied, one after another\
> in link order. While they run the machine reports \`friendly\_status: running\_scripts\` and\
> cannot be connected to.\
> \
> Scripts are written for one OS (\`os\`): a PowerShell script (\`.ps1\`) for Windows machines or a\
> bash script (\`.sh\`) for Linux machines, and can only be linked to machines of that OS. They\
> run with the Vagon agent's privileges (\`LOCAL SYSTEM\` on Windows, \`root\` on Linux) before the\
> user connects, so they can install and configure software but cannot reach the interactive\
> desktop. A script is immutable: to change it, create a new one. \`linked\_machine\_count\` is\
> the number of machines the script is currently linked to.\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/scripts":{"get":{"summary":"List Scripts","responses":{"200":{"description":"The organization's preloaded-scripts pool","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ListScriptsResponse"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"Returns every script in the organization's **preloaded-scripts pool**, newest first.\n\nPreloaded scripts are switched on per organization from the backoffice; while off, every route\nunder this tag answers `4236`.\n\nA preloaded script is created once in the pool and then **linked** to any number of the\norganization's machines (`POST /machines/{id}/scripts/link`), each link saying whether the\nscript runs at the start of **every session** or **once**. A machine runs its linked scripts\nwhen its next session starts, after its preloaded files have been copied, one after another\nin link order. While they run the machine reports `friendly_status: running_scripts` and\ncannot be connected to.\n\nScripts are written for one OS (`os`): a PowerShell script (`.ps1`) for Windows machines or a\nbash script (`.sh`) for Linux machines, and can only be linked to machines of that OS. They\nrun with the Vagon agent's privileges (`LOCAL SYSTEM` on Windows, `root` on Linux) before the\nuser connects, so they can install and configure software but cannot reach the interactive\ndesktop. A script is immutable: to change it, create a new one. `linked_machine_count` is\nthe number of machines the script is currently linked to.\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |"}}},"components":{"schemas":{"ListScriptsResponse":{"allOf":[{"$ref":"#/components/schemas/BaseResponse"},{"type":"object","properties":{"scripts":{"type":"array","items":{"$ref":"#/components/schemas/Script"}}}}]},"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Script":{"type":"object","properties":{"id":{"type":"string"},"type":{"type":"string"},"attributes":{"type":"object","properties":{"name":{"type":"string"},"os":{"type":"string","enum":["windows","linux"]},"size":{"type":"integer","description":"Size in bytes"},"checksum":{"type":"string","description":"SHA-256 of the script body, hex"},"created_at":{"type":"string","format":"date-time"},"linked_machine_count":{"type":"integer","description":"Machines the script is currently linked to (list endpoint only)"}}}}},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```

## Create Script

> Adds a script to the pool. The body travels in the request (\`script\_body\`, up to \*\*1 MB\*\*)\
> and is stored as is; there is no separate upload step.\
> \
> \`name\` must be a bare file name (no path separators), unique inside the pool, and it must\
> end with the extension of its OS: \`.ps1\` for \`windows\`, \`.sh\` for \`linux\`.\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\
> \| Content-Type | application/json |\
> \
> \### Body\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| name\\\* | string | Script file name, \`.ps1\` or \`.sh\` |\
> \| os\\\* | string | \`windows\` or \`linux\` |\
> \| script\_body\\\* | string | The script, up to 1 MB |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/scripts":{"post":{"summary":"Create Script","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateScriptRequest"}}}},"responses":{"200":{"description":"The new script","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptResponse"}}}},"400":{"description":"Invalid name, os or empty body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error400Response"}}}},"4229":{"description":"Script size exceeds the maximum allowed size (1 MB)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4229Response"}}}},"4230":{"description":"A script with that name already exists","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4230Response"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"Adds a script to the pool. The body travels in the request (`script_body`, up to **1 MB**)\nand is stored as is; there is no separate upload step.\n\n`name` must be a bare file name (no path separators), unique inside the pool, and it must\nend with the extension of its OS: `.ps1` for `windows`, `.sh` for `linux`.\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\n| Content-Type | application/json |\n\n### Body\n\n| Name | Type | Description |\n| --- | --- | --- |\n| name\\* | string | Script file name, `.ps1` or `.sh` |\n| os\\* | string | `windows` or `linux` |\n| script_body\\* | string | The script, up to 1 MB |"}}},"components":{"schemas":{"CreateScriptRequest":{"type":"object","required":["name","os","script_body"],"properties":{"name":{"type":"string"},"os":{"type":"string","enum":["windows","linux"]},"script_body":{"type":"string","description":"The script, up to 1 MB"}}},"ScriptResponse":{"allOf":[{"$ref":"#/components/schemas/BaseResponse"},{"type":"object","properties":{"script":{"$ref":"#/components/schemas/Script"}}}]},"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Script":{"type":"object","properties":{"id":{"type":"string"},"type":{"type":"string"},"attributes":{"type":"object","properties":{"name":{"type":"string"},"os":{"type":"string","enum":["windows","linux"]},"size":{"type":"integer","description":"Size in bytes"},"checksum":{"type":"string","description":"SHA-256 of the script body, hex"},"created_at":{"type":"string","format":"date-time"},"linked_machine_count":{"type":"integer","description":"Machines the script is currently linked to (list endpoint only)"}}}}},"Error400Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error4229Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4230Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```

## Delete Script

> Removes the script from the pool. Refused while the script is linked to any machine: unlink\
> it everywhere first (\`POST /machines/{id}/scripts/unlink\`).\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\
> \
> \### Path Parameters\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| id\\\* | integer | Script ID |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/scripts/{id}":{"delete":{"summary":"Delete Script","responses":{"200":{"description":"Script removed from the pool","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BaseResponse"}}}},"404":{"description":"Script not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error404Response"}}}},"4233":{"description":"The script is still linked to at least one machine","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4233Response"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"Removes the script from the pool. Refused while the script is linked to any machine: unlink\nit everywhere first (`POST /machines/{id}/scripts/unlink`).\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\n\n### Path Parameters\n\n| Name | Type | Description |\n| --- | --- | --- |\n| id\\* | integer | Script ID |"}}},"components":{"schemas":{"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error404Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error4233Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```

## Link Script to Machines

> The reverse of \`POST /machines/{id}/scripts/link\`: links one pool script to one or more\
> machines, \*\*all or nothing\*\*, with a run mode per machine. On each machine the script is\
> appended to the existing run order. The two directions write the same links; use whichever\
> fits the call, for example this one to roll a script out to a group of machines.\
> \
> An API secret scoped to \`machine\_ids\` must cover every machine in the body.\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\
> \| Content-Type | application/json |\
> \
> \### Path Parameters\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| id\\\* | integer | Script ID |\
> \
> \### Body\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| machines\\\* | array | Objects with \`machine\_id\` (integer) and optional \`run\_mode\` (\`once\`, the default, or \`every\_session\`) |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/scripts/{id}/link":{"post":{"summary":"Link Script to Machines","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LinkScriptMachinesRequest"}}}},"responses":{"200":{"description":"The machines the script was linked to, in the order given, each with the script's position in that machine's run order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LinkScriptMachinesResponse"}}}},"400":{"description":"machines missing or empty, a repeated machine_id, or an unknown run_mode","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error400Response"}}}},"404":{"description":"Script or one of the machines not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error404Response"}}}},"4231":{"description":"One of the machines runs the other operating system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4231Response"}}}},"4232":{"description":"The script is already linked to one of the machines","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4232Response"}}}},"4234":{"description":"One of the machines is at its limit (20 scripts)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4234Response"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required, or a machine in the body is outside the secret's machine scope","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"The reverse of `POST /machines/{id}/scripts/link`: links one pool script to one or more\nmachines, **all or nothing**, with a run mode per machine. On each machine the script is\nappended to the existing run order. The two directions write the same links; use whichever\nfits the call, for example this one to roll a script out to a group of machines.\n\nAn API secret scoped to `machine_ids` must cover every machine in the body.\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\n| Content-Type | application/json |\n\n### Path Parameters\n\n| Name | Type | Description |\n| --- | --- | --- |\n| id\\* | integer | Script ID |\n\n### Body\n\n| Name | Type | Description |\n| --- | --- | --- |\n| machines\\* | array | Objects with `machine_id` (integer) and optional `run_mode` (`once`, the default, or `every_session`) |"}}},"components":{"schemas":{"LinkScriptMachinesRequest":{"type":"object","required":["machines"],"properties":{"machines":{"type":"array","items":{"type":"object","required":["machine_id"],"properties":{"machine_id":{"type":"integer"},"run_mode":{"type":"string","enum":["once","every_session"],"default":"once"}}}}}},"LinkScriptMachinesResponse":{"allOf":[{"$ref":"#/components/schemas/BaseResponse"},{"type":"object","properties":{"machines":{"type":"array","items":{"$ref":"#/components/schemas/ScriptMachine"}}}}]},"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"ScriptMachine":{"type":"object","description":"A machine as seen from one pool script. `id` is the machine ID.","properties":{"id":{"type":"string"},"type":{"type":"string"},"attributes":{"type":"object","properties":{"name":{"type":"string"},"os":{"type":"string","enum":["windows","linux"]},"run_mode":{"type":"string","enum":["once","every_session"]},"position":{"type":"integer","description":"1-based place in that machine's run order"},"run_status":{"type":"string","enum":["pending","succeeded","failed"],"description":"Outcome of the script's last run on this machine"},"last_run_at":{"type":"string","format":"date-time","nullable":true},"last_exit_code":{"type":"integer","nullable":true},"last_error":{"type":"string","nullable":true},"linked_at":{"type":"string","format":"date-time"}}}}},"Error400Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error404Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4231Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4232Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4234Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```

## Unlink Script from Machines

> The reverse of \`POST /machines/{id}/scripts/unlink\`: unlinks one pool script from one or\
> more machines. Nothing changes on the machines themselves; the script simply stops running\
> at their session start. It stays in the pool.\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\
> \| Content-Type | application/json |\
> \
> \### Path Parameters\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| id\\\* | integer | Script ID |\
> \
> \### Body\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| machine\_ids\\\* | array | Machine IDs |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/scripts/{id}/unlink":{"post":{"summary":"Unlink Script from Machines","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptMachineIdsRequest"}}}},"responses":{"200":{"description":"Script unlinked from the machines","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BaseResponse"}}}},"400":{"description":"machine_ids missing or empty","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error400Response"}}}},"404":{"description":"Script not found, or it is not linked to one of the machines","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error404Response"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required, or a machine in the body is outside the secret's machine scope","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"The reverse of `POST /machines/{id}/scripts/unlink`: unlinks one pool script from one or\nmore machines. Nothing changes on the machines themselves; the script simply stops running\nat their session start. It stays in the pool.\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\n| Content-Type | application/json |\n\n### Path Parameters\n\n| Name | Type | Description |\n| --- | --- | --- |\n| id\\* | integer | Script ID |\n\n### Body\n\n| Name | Type | Description |\n| --- | --- | --- |\n| machine_ids\\* | array | Machine IDs |"}}},"components":{"schemas":{"ScriptMachineIdsRequest":{"type":"object","required":["machine_ids"],"properties":{"machine_ids":{"type":"array","items":{"type":"integer"}}}},"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error400Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error404Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```

## List Machine Scripts

> Returns the pool scripts linked to the machine in the order they run (\`position\`).\
> \`run\_mode\` is \`every\_session\` or \`once\`. \`run\_status\` is the outcome of the script's last run\
> on this machine: \`pending\` until it runs, then \`succeeded\` (exit code 0) or \`failed\`\
> (\`last\_exit\_code\`, \`last\_error\` with the tail of the script's error output, or the reason it\
> could not run, such as a timeout after 10 minutes). A \`once\` script runs at the next session\
> start only while it is \`pending\`; a \`once\` script that \`failed\` is not retried on its own:\
> unlink and link it again to get a fresh \`pending\` link. \`limit\` is the per-machine ceiling.\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\
> \
> \### Path Parameters\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| id\\\* | integer | Machine ID |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/machines/{id}/scripts":{"get":{"summary":"List Machine Scripts","responses":{"200":{"description":"Scripts linked to the machine, in run order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ListMachineScriptsResponse"}}}},"404":{"description":"Machine not found or does not belong to the organization","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error404Response"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"Returns the pool scripts linked to the machine in the order they run (`position`).\n`run_mode` is `every_session` or `once`. `run_status` is the outcome of the script's last run\non this machine: `pending` until it runs, then `succeeded` (exit code 0) or `failed`\n(`last_exit_code`, `last_error` with the tail of the script's error output, or the reason it\ncould not run, such as a timeout after 10 minutes). A `once` script runs at the next session\nstart only while it is `pending`; a `once` script that `failed` is not retried on its own:\nunlink and link it again to get a fresh `pending` link. `limit` is the per-machine ceiling.\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\n\n### Path Parameters\n\n| Name | Type | Description |\n| --- | --- | --- |\n| id\\* | integer | Machine ID |"}}},"components":{"schemas":{"ListMachineScriptsResponse":{"allOf":[{"$ref":"#/components/schemas/BaseResponse"},{"type":"object","properties":{"scripts":{"type":"array","description":"In run order","items":{"$ref":"#/components/schemas/MachineScript"}},"limit":{"type":"integer","description":"Per-machine ceiling on linked scripts"}}}]},"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"MachineScript":{"type":"object","description":"A pool script as seen from one machine. `id` is the script ID.","properties":{"id":{"type":"string"},"type":{"type":"string"},"attributes":{"type":"object","properties":{"name":{"type":"string"},"os":{"type":"string","enum":["windows","linux"]},"size":{"type":"integer","description":"Size in bytes"},"run_mode":{"type":"string","enum":["once","every_session"]},"position":{"type":"integer","description":"1-based place in the machine's run order"},"run_status":{"type":"string","enum":["pending","succeeded","failed"],"description":"Outcome of the script's last run on this machine"},"last_run_at":{"type":"string","format":"date-time","nullable":true},"last_exit_code":{"type":"integer","nullable":true},"last_error":{"type":"string","nullable":true},"linked_at":{"type":"string","format":"date-time"}}}}},"Error404Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```

## Link Scripts to Machine

> Links one or more pool scripts to the machine, \*\*all or nothing\*\*: if any script cannot be\
> linked, nothing is linked and the matching error is returned. The scripts are appended to\
> the machine's run order in the order given. Linking while the machine is running does not\
> touch the running session; the scripts run when its next session starts.\
> \
> A link is immutable: its \`run\_mode\` cannot be changed afterwards. To change it, unlink the\
> script and link it again with the new mode.\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\
> \| Content-Type | application/json |\
> \
> \### Path Parameters\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| id\\\* | integer | Machine ID |\
> \
> \### Body\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| scripts\\\* | array | Objects with \`script\_id\` (integer) and optional \`run\_mode\` (\`once\`, the default, or \`every\_session\`) |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/machines/{id}/scripts/link":{"post":{"summary":"Link Scripts to Machine","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LinkMachineScriptsRequest"}}}},"responses":{"200":{"description":"The newly created links, with their positions in the machine's run order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LinkMachineScriptsResponse"}}}},"400":{"description":"scripts missing or empty, a repeated script_id, or an unknown run_mode","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error400Response"}}}},"404":{"description":"Machine or one of the scripts not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error404Response"}}}},"4231":{"description":"One of the scripts is written for the other operating system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4231Response"}}}},"4232":{"description":"One of the scripts is already linked to this machine","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4232Response"}}}},"4234":{"description":"Linking these scripts would exceed the machine's limit (20 scripts)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4234Response"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"Links one or more pool scripts to the machine, **all or nothing**: if any script cannot be\nlinked, nothing is linked and the matching error is returned. The scripts are appended to\nthe machine's run order in the order given. Linking while the machine is running does not\ntouch the running session; the scripts run when its next session starts.\n\nA link is immutable: its `run_mode` cannot be changed afterwards. To change it, unlink the\nscript and link it again with the new mode.\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\n| Content-Type | application/json |\n\n### Path Parameters\n\n| Name | Type | Description |\n| --- | --- | --- |\n| id\\* | integer | Machine ID |\n\n### Body\n\n| Name | Type | Description |\n| --- | --- | --- |\n| scripts\\* | array | Objects with `script_id` (integer) and optional `run_mode` (`once`, the default, or `every_session`) |"}}},"components":{"schemas":{"LinkMachineScriptsRequest":{"type":"object","required":["scripts"],"properties":{"scripts":{"type":"array","description":"In the order the scripts should run, after the machine's existing links","items":{"type":"object","required":["script_id"],"properties":{"script_id":{"type":"integer"},"run_mode":{"type":"string","enum":["once","every_session"],"default":"once"}}}}}},"LinkMachineScriptsResponse":{"allOf":[{"$ref":"#/components/schemas/BaseResponse"},{"type":"object","properties":{"scripts":{"type":"array","items":{"$ref":"#/components/schemas/MachineScript"}}}}]},"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"MachineScript":{"type":"object","description":"A pool script as seen from one machine. `id` is the script ID.","properties":{"id":{"type":"string"},"type":{"type":"string"},"attributes":{"type":"object","properties":{"name":{"type":"string"},"os":{"type":"string","enum":["windows","linux"]},"size":{"type":"integer","description":"Size in bytes"},"run_mode":{"type":"string","enum":["once","every_session"]},"position":{"type":"integer","description":"1-based place in the machine's run order"},"run_status":{"type":"string","enum":["pending","succeeded","failed"],"description":"Outcome of the script's last run on this machine"},"last_run_at":{"type":"string","format":"date-time","nullable":true},"last_exit_code":{"type":"integer","nullable":true},"last_error":{"type":"string","nullable":true},"linked_at":{"type":"string","format":"date-time"}}}}},"Error400Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error404Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4231Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4232Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4234Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```

## Unlink Scripts from Machine

> Unlinks the given pool scripts from the machine. Nothing changes on the machine itself;\
> the scripts simply stop running at session start. They stay in the pool.\
> \
> \### Headers\
> \
> \| Name | Type |\
> \| --- | --- |\
> \| Authorization\\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\
> \| Content-Type | application/json |\
> \
> \### Path Parameters\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| id\\\* | integer | Machine ID |\
> \
> \### Body\
> \
> \| Name | Type | Description |\
> \| --- | --- | --- |\
> \| script\_ids\\\* | array | Script IDs to unlink |

```json
{"openapi":"3.0.0","info":{"title":"Vagon Computers API","version":"1.0.15"},"servers":[{"url":"https://api.vagon.io/organization-management/v1"}],"paths":{"/machines/{id}/scripts/unlink":{"post":{"summary":"Unlink Scripts from Machine","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineScriptIdsRequest"}}}},"responses":{"200":{"description":"Scripts unlinked","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BaseResponse"}}}},"400":{"description":"script_ids missing or empty","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error400Response"}}}},"404":{"description":"Machine not found, or one of the scripts is not linked to it","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error404Response"}}}},"4236":{"description":"Preloaded scripts are not enabled for this organization (switched on from the backoffice)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4236Response"}}}},"4710":{"description":"Permission required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error4710Response"}}}}},"tags":["Preloaded Scripts"],"description":"Unlinks the given pool scripts from the machine. Nothing changes on the machine itself;\nthe scripts simply stop running at session start. They stay in the pool.\n\n### Headers\n\n| Name | Type |\n| --- | --- |\n| Authorization\\* | HMAC {key}:{signature}:{nonce}:{timestamp} |\n| Content-Type | application/json |\n\n### Path Parameters\n\n| Name | Type | Description |\n| --- | --- | --- |\n| id\\* | integer | Machine ID |\n\n### Body\n\n| Name | Type | Description |\n| --- | --- | --- |\n| script_ids\\* | array | Script IDs to unlink |"}}},"components":{"schemas":{"MachineScriptIdsRequest":{"type":"object","required":["script_ids"],"properties":{"script_ids":{"type":"array","items":{"type":"integer"}}}},"BaseResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error400Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"ErrorResponse":{"type":"object","properties":{"client_code":{"type":"integer"},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"}}},"Error404Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4236Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]},"Error4710Response":{"allOf":[{"$ref":"#/components/schemas/ErrorResponse"}]}}}}
```
