Skip to content
QwryAI
Documentation
Pages

Endpoints

Create a procedure

Create a procedure from its name, trigger and steps through a review; it stays unpublished until you publish it

create_procedure saves a new procedure the way the Procedures editor does: its name, its trigger and its steps together. You write steps as plain text; QwryAI builds the editor's document from them and links each Action a step runs to its published version. The call returns a review; nothing is saved until you apply it. The new procedure isn't live until it's published.

POSThttps://api.qwryai.com/public/v1/tools/create_procedure

Authentication

Send your API key as Authorization: Bearer YOUR_API_KEY; it needs the Change actions and procedures permission. See Authentication.

Body parameters

NameTypeRequiredDescription
chatbotIdstringYesThe agent's id, from list_agents.
namestringYesThe procedure's name, 1 to 100 characters.
descriptionstringNoA short description, up to 500 characters.
triggerobjectYesWhen the procedure starts, below.
stepsarrayYes1 to 15 steps, counting those inside branches, below.

trigger

FieldTypeRequiredDescription
whenToUsestringYesThe customer request that starts it, up to 500 characters. It can be empty only when a chip starts the procedure.
channelsarrayNoWhere it runs: conversation, widget, email, sms, whatsapp, instagram, facebook, messenger, telegram, tiktok, zendesk-messaging, zendesk, slack, api, phone, android_sdk, ios_sdk. Each channel once. Left out, every channel.
noReplyobjectNoNo reply chip: { "afterMinutes" }, 1 to 1,440. Starts after the customer has been silent this long.
repeatobjectNoRepeat chip: { "everyMinutes", "times" }. Starts again at this interval, 2 to 10 times in all, until the customer replies.
schedulesarrayNoSchedule chips, up to 10. get_authoring_schema with kind: "playbook" describes a schedule.
apiobjectNoAPI chip: {}. The procedure can be started for one contact with start_procedure_for_contact.
ticketOpened, ticketClosedobjectNoHelpdesk chips: {}. Starts in the conversation when its ticket opens or closes.

steps

StepShapeDescription
Instruction{ "kind": "instruction", "text" }One thing the agent does: ask, confirm, tell, or run one Action. Up to 1,000 characters.
Message{ "kind": "message", "text", "subject"? }Sent to the customer as written, with variables filled in. Up to 4,000 characters; subject (up to 200) is for email.
Branch{ "kind": "branch", "branches": [{ "condition", "steps" }], "otherwise"? }If, Else if and Otherwise. 1 to 4 conditions of up to 500 characters; each branch holds instruction and message steps, never another branch.

In step text, [[actionId]] runs an Action, using the actionId from List actions of an Action that is published. [[actionId#field.path]] uses a field of its result in a later step, and {{contact.email}} or {{contact.first_name|there}} inserts a variable, with an optional fallback after |.

Request example

Bash
curl -X POST 'https://api.qwryai.com/public/v1/tools/create_procedure' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "chatbotId": "YOUR_AGENT_ID",
    "name": "Lost loyalty card",
    "trigger": {
      "whenToUse": "The customer says they lost their loyalty card.",
      "channels": ["widget", "conversation", "email", "whatsapp"]
    },
    "steps": [
      { "kind": "instruction", "text": "Ask the customer for their loyalty card number and their email address." },
      { "kind": "instruction", "text": "Create a ticket for the lost card with [[ACTION_ID]]." },
      { "kind": "instruction", "text": "Tell the customer their ticket number is [[ACTION_ID#ticketId]]." }
    ]
  }'

Response

The review

JSON
{
  "success": true,
  "data": {
    "status": "review_required",
    "reviewId": "3b7e1c90-4f2a-4d68-a5b3-9e0c8d7f6a12",
    "tool": "create_procedure",
    "changes": [
      {
        "title": "Create unpublished Procedure draft: Lost loyalty card",
        "before": null,
        "after": {
          "trigger": {
            "whenToUse": "The customer says they lost their loyalty card.",
            "channels": ["widget", "conversation", "email", "whatsapp"]
          },
          "name": "Lost loyalty card",
          "steps": [
            "1. Ask the customer for their loyalty card number and their email address.",
            "2. Create a ticket for the lost card with @Create ticket.",
            "3. Tell the customer their ticket number is @Create ticket → ticketId."
          ]
        }
      }
    ],
    "unchanged": [],
    "expiresAt": "2026-12-01T10:15:00.000Z",
    "next": "Show these changes to the user. Call apply_change with this reviewId only after they approve; the review expires in 15 minutes."
  }
}

After you apply it

Apply with POST https://api.qwryai.com/public/v1/reviews/{reviewId}/apply:

JSON
{
  "success": true,
  "data": {
    "status": "succeeded",
    "reviewId": "3b7e1c90-4f2a-4d68-a5b3-9e0c8d7f6a12",
    "tool": "create_procedure",
    "data": {
      "applied": true,
      "effect": "saved_draft",
      "draftId": "playbook-draft:5a8d2c71-e94b-4f06-b3a2-7c1e0d9f4b68",
      "url": "/<workspace>/<agentId>/ai-actions/playbooks/playbook-draft%3A5a8d2c71-e94b-4f06-b3a2-7c1e0d9f4b68",
      "revision": 1,
      "receiptId": "<receiptId>",
      "triggerRevision": 1,
      "publicationChanged": false
    },
    "receipt": { "applied": true }
  }
}

draftId is the new procedure's id. publicationChanged is false: the procedure is saved but not live. Publish it from the Procedures page, or with publish_draft after show_pending_changes (both need Change agent settings). The receipt is shortened here.

Errors

HTTP statuscodewhen
400INVALID_ARGUMENTSAn argument failed the schema or the procedure's rules: a missing trigger, more than 15 steps, a step over its length, a nested branch, an unknown or unpublished [[actionId]], an unknown {{variable}}, or an empty whenToUse with no chip. message says which.
400CHATBOT_ID_REQUIREDchatbotId is missing or isn't a valid agent id.
403INSUFFICIENT_PERMISSIONThe key doesn't hold Change actions and procedures.
404CHATBOT_NOT_FOUNDNo agent with that chatbotId in your workspace.
409STALE_REVIEWOn apply: the review no longer matches what the server would save. Call the tool again.
429INTEGRATION_RATE_LIMIT_EXCEEDEDMore than 2,000 requests in 15 minutes for this key.
500TOOL_FAILEDThe tool failed on our side. Try again.

Authentication and plan errors are listed in Error Handling.

Explore the documentation