Rest API
Create or update a procedure
const url = 'https://api.unless.com/api/v1/ai/actions';const options = { method: 'POST', headers: { 'x-api-key': 'example', 'x-user-email': 'example', 'x-account-id': 'example', 'x-website-id': 'example', 'Content-Type': 'application/json' }, body: '{"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":[]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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-apiprocedure 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 forcommand: apiandcommand: documented-apiit must be the procedure’s ownactionId, because the AI dispatches the procedure by it - A
documented-apiprocedure requiresdocs,hostsandmethods, and is rejected with a400without them. Itsdescriptionmay be at most 2000 characters, andvariablesmust be empty, because the AI composes the whole request itself - A
documented-apiprocedure is only offered to the AI withsmartAction: trueand adescription. Without either it saves fine but is never used - A
documented-apiprocedure takes its credentials from the visitor’s secure profile throughauth, never from a stored secret - Set
verifiedCustomersOnlyexplicitly on a procedure that reads or changes a customer’s own data. Absent reads as off - Generate the
actionIdyourself when creating a procedure, soargumentscan carry the same value in the same request. The API generates one when you omit it, which is too late forargumentsto reference accountIdandwebsiteIdare 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
400naming the field inissues[].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
smartActionexplicitly. 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 bodyis a string containing JSON, not a nested object- For
apiprocedures, credentials belong inheadersas a{{placeholder}}resolved from the visitor’s secure profile. A value declared invariablesends 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
Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”Your API key from account settings.
The email address of your user.
The ID of your account. You can find this in the account settings.
The ID of the workspace you want to use.
Request Bodyrequired
Section titled “Request Bodyrequired”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.
object
Unique identifier for this procedure.
Display name, also what the AI refers to when it decides to run the procedure.
What the procedure does. The AI reads this when deciding whether it applies.
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.
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.
Whether the procedure is live. Procedures saved before this field existed are treated as enabled and backfilled on read.
When true the AI fills the variables from the conversation. When false the visitor is asked for each one.
Whether running this procedure hands the conversation to a human.
Only visitors identified with a valid identify JWT can run the procedure. Others are asked to log in first. Absent reads as off.
Extra instructions for the AI on how to use this procedure.
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.
One value collected from the visitor or filled by the AI before the procedure runs.
object
Referenced as {{name}} in the endpoint, headers or body.
What the value is. Shown to the visitor, and what the AI matches against when filling it itself.
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.
Ask the visitor even when the AI could infer the value.
Pattern the collected value must match.
Fixed set of choices offered to the visitor.
object
Only collect this variable when the named variable has dependsOnVariableValue.
Restrict the procedure to these AI segments. Empty or absent means every segment.
Restrict the procedure to these audiences (ruleIds). The visitor must be in at least one of them. Empty or absent means everyone.
Shown before the visitor is asked for the variables.
Shown just before the procedure executes.
Run the procedure when the AI could not answer the question.
Seconds of inactivity before the timeout trigger fires.
JavaScript expression that must be truthy for the procedure to be offered.
Training documents that reference this procedure, so you can see which knowledge triggers it. Read-only, and only returned by the list operation.
object
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.
HTTP method of the call the procedure makes.
URL to call. Resolves {{variable}} placeholders only, not the <<Name>> runtime ones.
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
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>>.
Schema the dashboard uses to validate the body. Not enforced by the API.
object
JavaScript that reshapes the API response before the AI uses it.
What happens after a successful call.
One step run after the procedure succeeded or failed.
object
What the step does. display-message shows text in the chat, translated into the conversation language.
Identifier for the step. Generated when omitted.
The text to show. Only for display-message.
The question to send back to the AI. Only for call-query.
Label shown for the follow-up query. Only for call-query.
System prompt used for the follow-up query. Only for call-query.
What happens after a failed call.
One step run after the procedure succeeded or failed.
object
What the step does. display-message shows text in the chat, translated into the conversation language.
Identifier for the step. Generated when omitted.
The text to show. Only for display-message.
The question to send back to the AI. Only for call-query.
Label shown for the follow-up query. Only for call-query.
System prompt used for the follow-up query. Only for call-query.
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.
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.
documented-api only. The HTTP methods the AI may use. Allow only GET unless the AI really has to change data.
documented-api only. Path prefix applied to every path in docs, such as /v2. Starts with /, with no query string, fragment or ...
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.
object
object
The secure profile trait holding the token. Defaults to authToken.
object
object
Letters, digits and dashes only. Each header may only be set once.
The secure profile trait that holds the value. The only way to send a secret.
Also make this trait available as a {{placeholder}} in paths, query parameters and bodies. Never set it for a key or a token.
object
Letters, digits and dashes only. Each header may only be set once.
A value that is not a secret. It may contain {{placeholders}}, resolved from the chat metadata and the secure profile. Anything the browser can set, the browser can change, so only use it for identifiers the API checks itself.
documented-api only. How many requests the AI may make in one conversation. Defaults to 20.
documented-api only. Responses are cut to this many characters before the AI reads them. Defaults to 20000.
documented-api only. Request timeout in milliseconds. Defaults to 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": []}Responses
Section titled “Responses”The procedure was created or updated.
object
ID of the procedure that was written. Echoes the actionId you sent, or the generated one when you created a procedure.
Example
{ "actionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "message": "Procedure upserted"}Bad request - missing body or websiteId.
Unauthorized - invalid API key.