Skip to content

Rest API

Create or update a procedure

POST
/api/v1/ai/actions
curl --request POST \
--url https://api.unless.com/api/v1/ai/actions \
--header 'Content-Type: application/json' \
--header 'x-account-id: example' \
--header 'x-api-key: example' \
--header 'x-user-email: example' \
--header 'x-website-id: example' \
--data '{ "actionId": "3f6c1b52-9a4e-4c8d-9f1a-2b7d5e0c4a13", "arguments": "3f6c1b52-9a4e-4c8d-9f1a-2b7d5e0c4a13", "name": "Look up order status", "description": "Retrieves the status of an order from the shop backend.", "command": "api", "enabled": true, "smartAction": true, "method": "GET", "endpoint": "https://api.example.com/orders/{{orderId}}", "headers": { "x-api-key": "{{shopApiKey}}" }, "body": "{}", "bodyType": "json", "variables": [ { "name": "orderId", "description": "The order number the visitor is asking about", "type": "string" } ], "onSuccessPostActions": [ { "command": "display-message", "text": "Here is the status of your order." } ], "onErrorPostActions": [] }'

Create a new procedure, or update an existing one by passing its actionId. The body is the whole procedure, not a patch: fields you leave out are not preserved, so fetch the procedure first and send it back with your changes applied.

Use cases

  • Automation: Give the AI an API call it can make on the visitor’s behalf
  • Connect a whole API: Give the AI a documented-api procedure with an API reference, so it composes the requests itself instead of calling one fixed endpoint
  • Account setup: Provision the standard procedures for a new workspace
  • Maintenance: Enable, disable or retarget an existing procedure by passing its actionId

Notes

  • Send arguments. It is the command’s input and is required, and for command: api and command: documented-api it must be the procedure’s own actionId, because the AI dispatches the procedure by it
  • A documented-api procedure requires docs, hosts and methods, and is rejected with a 400 without them. Its description may be at most 2000 characters, and variables must be empty, because the AI composes the whole request itself
  • A documented-api procedure is only offered to the AI with smartAction: true and a description. Without either it saves fine but is never used
  • A documented-api procedure takes its credentials from the visitor’s secure profile through auth, never from a stored secret
  • Set verifiedCustomersOnly explicitly on a procedure that reads or changes a customer’s own data. Absent reads as off
  • Generate the actionId yourself when creating a procedure, so arguments can carry the same value in the same request. The API generates one when you omit it, which is too late for arguments to reference
  • accountId and websiteId are taken from the auth headers; anything you send in the body for them is overwritten
  • The body is validated before anything is stored. A missing required field or a value outside a documented enum comes back as a 400 naming the field in issues[].path, and nothing is written
  • Fields the server owns are ignored rather than rejected, so echoing a procedure you just read back into a write is safe
  • Set smartAction explicitly. It decides whether the AI fills the variables from the conversation or the visitor is asked for each one, and it is stored as sent
  • body is a string containing JSON, not a nested object
  • For api procedures, credentials belong in headers as a {{placeholder}} resolved from the visitor’s secure profile. A value declared in variables ends up in the chat data, which is stored with the conversation and sent to the model
  • Deleting a procedure is not available with an API key, only from the dashboard
x-api-key
required
string

Your API key from account settings.

x-user-email
required
string

The email address of your user.

x-account-id
required
string

The ID of your account. You can find this in the account settings.

x-website-id
required
string

The ID of the workspace you want to use.

The procedure to store. Common fields are described by the Procedure schema; the properties below are the ones an api or a documented-api procedure adds.

Media typeapplication/json
object
accountId
string
websiteId
string
actionId

Unique identifier for this procedure.

string
name
required

Display name, also what the AI refers to when it decides to run the procedure.

string
description

What the procedure does. The AI reads this when deciding whether it applies.

string
nullable
command
required

What the procedure executes. api calls an HTTP endpoint, documented-api lets the AI call any endpoint of an API from its reference in docs, mcp invokes an MCP tool, direct-answer supplies a fixed answer, and the rest drive the component. Each command reads its input from arguments.

string
Allowed values: api mcp direct-answer rephrase-and-answer redirect-to-url start-experience start-live-chat execute-custom-javascript switch-segment send-message-to-segment send-message-to-segment-and-switch resend-message-to-segment-and-switch open-image open-video documented-api
arguments
required

The command’s input. What it has to contain depends on command, and a procedure whose arguments is wrong is stored happily but fails when the AI tries to run it. For api, documented-api and rephrase-and-answer it must be the procedure’s own actionId. For mcp it is the MCP tool ID, for direct-answer the answer text, for redirect-to-url the URL, for start-experience the component ID, for execute-custom-javascript the code, for the segment commands the topic (and message), and for open-image and open-video the media URL. Only start-live-chat takes no input.

string
nullable
enabled

Whether the procedure is live. Procedures saved before this field existed are treated as enabled and backfilled on read.

boolean
nullable
smartAction

When true the AI fills the variables from the conversation. When false the visitor is asked for each one.

boolean
nullable
escalate

Whether running this procedure hands the conversation to a human.

boolean
verifiedCustomersOnly

Only visitors identified with a valid identify JWT can run the procedure. Others are asked to log in first. Absent reads as off.

boolean
nullable
guidance

Extra instructions for the AI on how to use this procedure.

string
nullable
variables

The values collected before the procedure runs, referenced as {{name}} in the endpoint, the headers and the body. They resolve from the chat metadata, which also carries every string field of the visitor’s secure profile. An unresolved {{name}} is sent verbatim rather than raising an error.

Array<object>

One value collected from the visitor or filled by the AI before the procedure runs.

object
name

Referenced as {{name}} in the endpoint, headers or body.

string
description

What the value is. Shown to the visitor, and what the AI matches against when filling it itself.

string
type

How the value is collected and validated. string is a single-line input, multiline a text area, number a numeric input, email validates an address, regex validates against the regex field, and select offers the options as a dropdown. No other value is accepted: boolean, date and phone are reserved but not implemented, and storing one of them makes the get procedures endpoint fail for the whole workspace.

string
Allowed values: string multiline number email regex select
optional
boolean
forceCollection

Ask the visitor even when the AI could infer the value.

boolean
regex

Pattern the collected value must match.

string
nullable
options

Fixed set of choices offered to the visitor.

Array<object>
nullable
object
label
string
value
string
dependsOnVariable

Only collect this variable when the named variable has dependsOnVariableValue.

string
nullable
dependsOnVariableValue
string
nullable
availability
string
nullable
Allowed values: ALWAYS DURING_OPENING_HOURS OUTSIDE_OPENING_HOURS
enabledSegments

Restrict the procedure to these AI segments. Empty or absent means every segment.

Array<string>
nullable
enabledAudiences

Restrict the procedure to these audiences (ruleIds). The visitor must be in at least one of them. Empty or absent means everyone.

Array<string>
nullable
preCollectionMessage

Shown before the visitor is asked for the variables.

string
nullable
preExecuteMessage

Shown just before the procedure executes.

string
nullable
immediatelyExecute
boolean
nullable
triggerAfterResponse
boolean
triggerAfterUnanswered

Run the procedure when the AI could not answer the question.

boolean
triggerAfterTimeout
boolean
triggerAfterTimeoutTime

Seconds of inactivity before the timeout trigger fires.

number
skipTranslation
boolean
nullable
javascriptDisplayTrigger

JavaScript expression that must be truthy for the procedure to be offered.

string
nullable
documentsTriggeringAction

Training documents that reference this procedure, so you can see which knowledge triggers it. Read-only, and only returned by the list operation.

Array<object>
object
actionId

ID of the procedure. Pass the ID of an existing procedure to update it. To create one, generate a UUID yourself and send it here, so arguments can carry the same value in the same request. Omitting it makes the API generate an ID, which leaves an api procedure with no way to reference itself.

string
method

HTTP method of the call the procedure makes.

string
Allowed values: GET POST
endpoint

URL to call. Resolves {{variable}} placeholders only, not the <<Name>> runtime ones.

string
nullable
headers

Request headers. The only place a credential placeholder may appear, as {{authToken}} or another field of the visitor’s secure profile. Header values resolve {{variable}} placeholders only, not the <<Name>> runtime ones.

object
key
additional properties
string
body

Request body as a string. For a JSON body this is JSON encoded as a string, not a nested object. Sent on POST only. As well as {{variable}} placeholders, the body is the one field that also resolves the runtime placeholders <<AccountId>>, <<WebsiteId>>, <<ChatData>>, <<AuthToken>> and <<VisitorMemory>>.

string
nullable
bodyType
string
Allowed values: json plain
bodySchema

Schema the dashboard uses to validate the body. Not enforced by the API.

object
transformer

JavaScript that reshapes the API response before the AI uses it.

string
nullable
onSuccessPostActions

What happens after a successful call.

Array<object>

One step run after the procedure succeeded or failed.

object
command
required

What the step does. display-message shows text in the chat, translated into the conversation language.

string
Allowed values: display-message call-query
id

Identifier for the step. Generated when omitted.

string
text

The text to show. Only for display-message.

string
query

The question to send back to the AI. Only for call-query.

string
promptLabel

Label shown for the follow-up query. Only for call-query.

string
systemPrompt

System prompt used for the follow-up query. Only for call-query.

string
onErrorPostActions

What happens after a failed call.

Array<object>

One step run after the procedure succeeded or failed.

object
command
required

What the step does. display-message shows text in the chat, translated into the conversation language.

string
Allowed values: display-message call-query
id

Identifier for the step. Generated when omitted.

string
text

The text to show. Only for display-message.

string
query

The question to send back to the AI. Only for call-query.

string
promptLabel

Label shown for the follow-up query. Only for call-query.

string
systemPrompt

System prompt used for the follow-up query. Only for call-query.

string
docs

documented-api only. The API reference the AI reads before it composes a request, in markdown with one ## METHOD /path heading per endpoint, followed by what the endpoint is for, its parameters (which are required and what values they accept) and a short example. Paths are relative to basePath. Write it for a language model, and leave out endpoints a support assistant would never need, such as admin, billing management, webhook and health endpoints.

string
>= 1 characters <= 64000 characters
hosts

documented-api only. The bare hostnames the AI may call, such as api.example.com. No scheme, port, path, wildcard or IP address, and no .local or .internal hosts.

Array<string>
>= 1 items <= 5 items
methods

documented-api only. The HTTP methods the AI may use. Allow only GET unless the AI really has to change data.

Array<string>
>= 1 items
Allowed values: GET HEAD POST PUT PATCH DELETE
basePath

documented-api only. Path prefix applied to every path in docs, such as /v2. Starts with /, with no query string, fragment or ...

string
nullable
auth

documented-api only. How each request is authenticated. Every value comes from the visitor’s secure profile, the traits in the identify JWT, so a procedure never stores a secret. bearer sends Authorization: Bearer <trait>, headers sends up to 6 headers, each from a trait or a value that is not a secret. Defaults to none.

One of:
object
type
required
string
Allowed values: none
maxCallsPerConversation

documented-api only. How many requests the AI may make in one conversation. Defaults to 20.

integer
>= 1 <= 100
maxResponseChars

documented-api only. Responses are cut to this many characters before the AI reads them. Defaults to 20000.

integer
>= 500 <= 50000
timeoutMs

documented-api only. Request timeout in milliseconds. Defaults to 10000.

integer
>= 1000 <= 10000

Example

{
"actionId": "3f6c1b52-9a4e-4c8d-9f1a-2b7d5e0c4a13",
"arguments": "3f6c1b52-9a4e-4c8d-9f1a-2b7d5e0c4a13",
"name": "Look up order status",
"description": "Retrieves the status of an order from the shop backend.",
"command": "api",
"enabled": true,
"smartAction": true,
"method": "GET",
"endpoint": "https://api.example.com/orders/{{orderId}}",
"headers": {
"x-api-key": "{{shopApiKey}}"
},
"body": "{}",
"bodyType": "json",
"variables": [
{
"name": "orderId",
"description": "The order number the visitor is asking about",
"type": "string"
}
],
"onSuccessPostActions": [
{
"command": "display-message",
"text": "Here is the status of your order."
}
],
"onErrorPostActions": []
}

The procedure was created or updated.

Media typeapplication/json
object
actionId

ID of the procedure that was written. Echoes the actionId you sent, or the generated one when you created a procedure.

string
message
string

Example

{
"actionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"message": "Procedure upserted"
}

Bad request - missing body or websiteId.

Unauthorized - invalid API key.