Skip to content

Update script source

PUT https://rest.haasapi.com/v1/scripts/{script_id}/source

Replaces the script’s source text entirely, recompiles it, and answers the compile verdict. A source that does not compile is still saved - is_valid: false and the compile.errors say what to fix. Bots keep running their loaded copy until restarted.

Requires the scripts scope.

{
"source": "-- v1 qa edit\nLog('hello')"
}
Field Type Description
source string The new HaasScript source, as plain text - it replaces the previous source entirely. Compiled on save; a source that does not compile is still saved (with is_valid: false).
Terminal window
curl "https://rest.haasapi.com/v1/scripts/{script_id}/source" \
-X PUT \
-H "Authorization: Bearer hk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"-- v1 qa edit\nLog('hello')"}'

200 OK. Returns a ScriptSourceUpdated.

{
"script_id": "c33916a3697742dfb93888d07cf887d2",
"compile": {
"is_valid": true,
"errors": []
}
}
Field Type Description
script_id string The script the new source was saved to.
compile ScriptCompile The verdict of compiling the new source.
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.
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.

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)
404 No accessible script with that id. (code: script_not_found)
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"
}