Create a script
POST https://rest.haasapi.com/v1/scripts
Creates a Lua HaasScript from a name and source text, compiles it, and answers 201 with the created script (the single-script shape, compile verdict included). A source that does not compile still creates the script - is_valid: false and the compile.errors say what to fix.
Requires the scripts scope.
Request body
Section titled “Request body”{ "name": "v1-qa-scripts-verify", "source": "-- v1 qa\nLog(Close())", "description": "v1 scripts API verification, safe to delete"}CreateScriptRequest
Section titled “CreateScriptRequest”| Field | Type | Description |
|---|---|---|
name |
string | Script name, 1-150 characters. |
source |
string | The HaasScript source, as plain text. Compiled on creation; a script that does not compile is still created (with is_valid: false) so you can fix it with PUT /scripts/{script_id}/source. |
description |
string, nullable | Optional description. |
Example request
Section titled “Example request”curl "https://rest.haasapi.com/v1/scripts" \ -X POST \ -H "Authorization: Bearer hk_live_YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{"name":"v1-qa-scripts-verify","source":"-- v1 qa\nLog(Close())","description":"v1 scripts API verification, safe to delete"}'Response
Section titled “Response”201 Created. Returns a ScriptDetail.
{ "script_id": "c33916a3697742dfb93888d07cf887d2", "name": "v1-qa-scripts-verify", "description": "v1 scripts API verification, safe to delete", "type": "lua", "is_valid": false, "created_at": "2026-08-29T20:11:30Z", "updated_at": "2026-08-29T20:11:30Z", "source": "-- v1 qa\nLog(Close())", "compile": { "is_valid": false, "errors": [ { "message": "Unknown reference: Close", "line": 2 } ] }}Fields
Section titled “Fields”ScriptDetail
Section titled “ScriptDetail”| Field | Type | Description |
|---|---|---|
script_id |
string | Script identifier - the id the script endpoints and POST /v1/bots accept. |
name |
string | User-chosen script name. |
description |
string, nullable | User-chosen description. null when the script has none. |
type |
string | Script kind: lua or visual. |
is_valid |
boolean | Whether the script’s last compile succeeded. Only valid scripts can run on a bot. |
created_at |
string, nullable | When the script was created, RFC 3339 UTC. null when unknown. |
updated_at |
string, nullable | When the script was last updated, RFC 3339 UTC. null when unknown. |
source |
string | The HaasScript source, as plain text. |
compile |
ScriptCompile | The verdict of the script’s last compile. |
ScriptCompile
Section titled “ScriptCompile”| Field | Type | Description |
|---|---|---|
is_valid |
boolean | Whether the source compiled. Only valid scripts can run on a bot. |
errors |
array of ScriptCompileError | The compile errors; empty when the source compiled. |
ScriptCompileError
Section titled “ScriptCompileError”| Field | Type | Description |
|---|---|---|
message |
string | What the compiler rejected - an unknown command, a syntax error, …. |
line |
integer (int32), nullable | 1-based line in the source the error points at. null when the compiler gave no position. |
Errors
Section titled “Errors”All errors are RFC 9457 problem documents.
| Status | Description |
|---|---|
400 |
The request is malformed (invalid limit, unusable cursor, …). (code: invalid_request) |
401 |
Missing, malformed, disabled, or revoked API key. (code: invalid_api_key) |
403 |
Creation refused: your plan does not allow creating scripts. (code: forbidden) |
409 |
A request with this Idempotency-Key is still being processed. (code: idempotency_in_progress) |
422 |
The Idempotency-Key was already used with a different request. (code: idempotency_key_reuse) |
500 |
An unexpected error inside the API. Nothing about the request caused it; retry, and quote the instance value if it persists. (code: internal_error) |
502 |
An internal service answered in a way the API could not serve. Retry. (code: upstream_error) |
503 |
The request could not be served right now. Retry with the same key - do not discard it. (code: temporarily_unavailable) |
504 |
An internal service did not answer within the deadline. Retry with backoff. (code: upstream_timeout) |
{ "type": "https://docs.haasapi.com/errors/invalid_request", "title": "Invalid request", "status": 400, "detail": "The request is malformed (invalid limit, unusable cursor, …).", "code": "invalid_request"}