Skip to main content
These endpoints let you create, read, update, and delete hooks — the setup, teardown, and runtime scripts that prepare app state and bridge your backend with the Autosana agent. All requests require an API key in the X-API-Key header. See API Reference for authentication and the standard 401 / 403 / 429 / 500 error shapes shared by every endpoint on this page.
This API covers hook CRUD and test execution. To attach a hook as a setup/teardown step on a flow or suite, use the dashboard or the Autosana MCP. Runtime hooks need no attachment — reference them from flow instructions as ${hooks:Hook Name}.

List Hooks

GET /api/v1/hooks — Returns 200 OK

Query Parameters

string
Optional. Filter to setup/teardown hooks attached to this flow. Runtime hooks (embedded in flow instructions as ${hooks:NAME}) are NOT returned. Mutually exclusive with suite_id.
string
Optional. Filter to setup/teardown hooks attached to this suite. Mutually exclusive with flow_id.

Example Request

Response Fields

array
List of hook objects.
integer
Total number of hooks returned.

Example Response


Create Hook

Create a new hook. Reference it in flow instructions as ${hooks:NAME} for runtime use, or attach it as a setup/teardown hook from the dashboard.
POST /api/v1/hooks — Returns 201 Created

Request Body

string
required
Name of the hook (1–255 characters). Used as the ${hooks:NAME} reference in flow instructions.
string
required
The script content (curl command, Python source, etc.).
string
required
One of curl, python, javascript, typescript, bash, launch_args. See Hook Types for what each one runs.
string
Optional description of what the hook does.

Example Request

Example Response


Get Hook

GET /api/v1/hooks/{hook_id} — Returns 200 OK with the same shape as items in List Hooks, or 404 if the hook does not exist.
string
required
UUID of the hook.

Update Hook

Update a hook’s script, script_type, and/or description. Omitted fields are left unchanged.
Hook names cannot be updated. Runtime hooks reference hooks by name in flow instructions (${hooks:NAME}), so renaming would silently break those references. To rename safely: create a new hook, update every flow that references the old name to use the new one, then delete the old hook. There is no atomic rename.
PATCH /api/v1/hooks/{hook_id} — Returns 200 OK. 400 if no recognized fields are provided. 404 if the hook does not exist.
string
required
UUID of the hook.
string
New script content.
string
New script type (curl, python, javascript, typescript, bash, launch_args).
string | null
New description. Pass "" or null to clear.

Delete Hook

Deletes the hook. Past run history (the rows that referenced this hook when they ran) is preserved. If the hook is currently attached to one or more flows or suites, the call returns 409 Conflict with the names of the affected resources. Pass ?force=true to detach and delete anyway — the setup/teardown attachments are deactivated as part of the delete.
DELETE /api/v1/hooks/{hook_id} — Returns 204 No Content. 409 if the hook is in use and force=false. 404 if the hook does not exist.
string
required
UUID of the hook.
boolean
Defaults to false. When true, deletes the hook even if it’s attached to flows or suites — those attachments are deactivated.
force=true detaches the hook from every flow and suite at once. There’s no per-attachment opt-out, no dry-run, and no undo. Inspect the 409 conflict response (without force) first to see exactly which flows/suites will be affected.

Example 409 Response


Test Hook

Execute the hook in isolation against a chosen environment and return the result. Uses a shorter 60-second timeout for fast feedback.
POST /api/v1/hooks/{hook_id}/test — Returns 200 OK. 404 if the hook does not exist.

Request Body

string
required
UUID of the environment whose env vars to inject.
string
Optional. Test a modified script without saving the changes — useful for CI to dry-run a proposed update before persisting it via PATCH /api/v1/hooks/{id}.

Example Request

Response Fields

boolean
Whether the hook executed successfully.
integer | null
Exit code (for scripts) or HTTP status (for curl).
string
Captured stdout/stderr from the sandbox.
integer
Wall-clock duration in milliseconds.
string | null
Category of failure when success=false (e.g. Execution timed out, Missing environment variable).