# Custom actions: connect your AI agent to any API > Call your own API, run code in the browser, or show an interactive widget, all from inside the conversation Custom actions connect your QwryAI agent to anything you can reach over an HTTPS API. The agent calls your endpoint, gets the JSON response back, and uses that data in its reply, so it can answer questions and do tasks that live in your own systems. A Custom action can also run code in the customer's browser or show an interactive widget in the chat. **Best for:** anything QwryAI doesn't have a built-in Action for: looking up records in your own systems, triggering a workflow, or showing a custom interface in the chat. **Common use cases:** * "Do you deliver to my postcode?" * "What's the status of my booking?" * "Look up my account balance" ![The Create Action gallery with the pointer on the Custom actions card.](annotated/01-card.webp "Create Action › Custom actions.") ## Action types When you create a Custom action, you pick a **type** that sets how it behaves: | Type | What it does | Channels | | - | - | - | | **Call API** | Calls your API and gives the response to the agent, which uses it in its reply. | Every channel, including WhatsApp, Messenger, Instagram, Email, Slack, API and Phone | | **Run client-side code** | Runs custom code on the client, through the [website embed](/docs/developer-guides/website-integration/client-side-custom-actions) or the mobile SDKs. Tick **Wait for response** to have the agent wait for the result. | Chat bubble, Help page, Center Stage, Android SDK, iOS SDK | | **Call API + show widget** | Calls your API and shows the results in a [widget](/docs/developer-guides/widgets/overview) in the chat. | Chat bubble, Help page, Center Stage | | **Show widget** | Shows a widget with fixed data or with data from the conversation, without calling an API. | Chat bubble, Help page, Center Stage | > [!NOTE] > > **Call API + show widget** and **Show widget** Actions have a **Widget** section where you attach a widget from **Build › Widgets** or create a new one. See [Widgets](/docs/developer-guides/widgets/overview). ## How to create the Action **1. Open Actions** In your [QwryAI dashboard](https://www.qwryai.com), select your agent and click **Build › Actions** in the sidebar. **2. Create the Action** Click **Create Action**, then the **Custom actions** card, and **Start customizing**. **Create Custom Action** opens with its sections: **General**, **Action type**, **API**, **Test response**, **Data access** and **Channels**. ![The Custom actions dialog with a sample chat and Start customizing.](annotated/01-card--open.webp "The Custom actions dialog.") **3. Configure General** See [General](#general), then click **Continue**. **4. Pick the Action type** **Call API** is selected by default, so **Continue** in General takes you straight to **API**. To use another [type](#action-types), open **Action type** and select it. **5. Configure the API** Add the data inputs the agent collects and the request it sends. See [API](#api), then click **Continue**. **6. Test the response** Check that the endpoint returns what you expect. See [Test response](#test-response), then click **Continue**. **7. Set Data access** Choose how much of the response the agent can see. See [Data access](#data-access), then click **Continue**. **8. Choose Channels and save** Turn the Action on or off for each configured channel, then click **Save**. The Action is saved to your agent's draft; click **Publish** in the top-right corner to make it live for customers. See [Drafts and publishing](/docs/user-guides/chatbot/drafts-and-publishing). ![In Create Action, selecting the Custom actions card and Start customizing, typing Check_delivery_area and a When to use description, selecting Continue, keeping Call API as the Action type and selecting Continue again to reach the API section.](walkthroughs/custom-action-create.gif) > [!TIP] > > You can also ask [Backstage](/docs/user-guides/chatbot/backstage) to build the Action for you. Describe what your agent should do and share your API docs, and Backstage sets up and tests the Action in the conversation. ## General **Action name:** a descriptive name, such as `Get_Order_Status`. The agent sees this name, so it helps it know when to use the Action. Names need 3 to 63 characters and can contain only letters, numbers, underscores and hyphens, with no spaces. ![Check_delivery_area typed in Action name.](annotated/03-name.webp "Name the Action.") **When to use:** a detailed description of when the agent should use this Action. Include the data it provides and example customer questions it helps answer. ![When to use filled in with example questions about delivery areas.](annotated/04-when.webp "Describe when the agent should call it.") **When not to use (optional):** cases where the agent should leave the Action alone, such as `Don't use this for delivery times or shipping costs.` ![When not to use filled in: not for delivery times or shipping costs.](annotated/05-when-not.webp "When not to use is optional.") To run the Action only as a [Procedure](/docs/user-guides/chatbot/procedures/procedures-overview) step, turn on [**Only use in Procedures**](/docs/user-guides/chatbot/actions/actions-overview#only-use-in-procedures). **When to use** is then hidden. ![The Action type section with Call API selected and the other types: Run client-side code, Call API + show widget and Show widget.](annotated/07-types.webp "Action type: Call API is the default.") ## API ### Collect data inputs for action The information the agent needs to perform the Action. The agent can find it in the chat history, ask the customer for it, or take it from the customer's details if they're available. Click **Add data input** for each one: * **Name:** the input's name. Use it in the request as `{{name}}`. * **Type:** **text**, **number**, **boolean**, **date** or **email**. * **Description:** a short sentence that tells the agent what to ask for. * **Array:** tick it to accept a list of values instead of one. ![One data input named postcode, of type text, with a description.](annotated/08-add-input.webp "Add the data the agent must collect.") ### API request The endpoint the agent calls to get data or send updates. You can use the data inputs in the URL or the request body. * **Method:** `GET`, `POST`, `PUT`, `PATCH` or `DELETE`. * **HTTPS URL:** the URL of your API. * **Add Variable:** inserts a variable. See [Variables](#variables). Below the URL, tabs hold the request's **Parameters**, **Headers** and **Body**. Use **Add key value pair** to add a parameter or header. The body must be **JSON**. ![The API request with Method GET and the URL https://api.zippopotam.us/au/ followed by a postcode variable.](annotated/09-url.webp "Put the input in the URL as a variable.") ![In the API section, selecting Add data input, naming it postcode with a description, then typing https://api.zippopotam.us/au/ in HTTPS URL and inserting the postcode variable with Add Variable.](walkthroughs/custom-action-api.gif) ### Variables **Add Variable** lists four groups. You can use them in the URL, **Parameters**, **Headers** and **Body**: | Group | Variables | | - | - | | **Input Variables** | Your data inputs, by **Name**, such as `{{postcode}}` | | **Static Variables** | `{{conversationId}}`, the current conversation; `{{userId}}`, for [identified users](/docs/developer-guides/website-integration/identity-verification); `{{callerPhone}}`, the caller's number on phone calls | | **Contact Data** | `{{contact.id}}`, `{{contact.external_id}}`, `{{contact.email}}`, `{{contact.name}}`, `{{contact.phonenumber}}`, `{{contact.stripe_accounts}}`, `{{contact.created_at}}`, `{{contact.updated_at}}` | | **Attributes** | The current contact's or conversation's attribute value, sent without asking the customer | For example, a `Get_Order_Status` Action could call `https://api.example.com/orders/{{orderNumber}}?email={{contact.email}}`, where `orderNumber` is a data input the agent asks the customer for. ### Authentication Authenticate with static **Headers** or **Parameters**, such as `Authorization: Bearer ` or `x-api-key: `. > [!WARNING] > > Anyone who can edit the Action can see its header and parameter values. Use an API key scoped to only what the Action needs. ## Test response Pick how to test, then click **Continue**: * **Live response:** test with live data from the API to make sure it's set up correctly. Enter a test value for each input and click **Test response**. * **Example response:** paste example JSON if the API isn't ready yet. ![The Test response section after testing postcode 2000, with the live JSON response listing Sydney suburbs.](annotated/11-test.webp "Test response calls the API with your test value.") ![In Test response, keeping Live response, typing 2000 as the test value for postcode, selecting Test response and scrolling through the JSON that lists the Sydney suburbs.](walkthroughs/custom-action-test.gif) ## Data access * **Full data access:** the agent can use everything in the response, for complete replies. * **Limited data access:** the agent sees only the fields you pick, for more controlled replies that protect sensitive data. A table lists every field in the test response with its size; tick the fields the agent may see. The selected response size is shown against the 20 KB limit. ![The Data access section with full and limited access options.](annotated/12-test-continue--open.webp "Data access: what the agent may read.") > [!TIP] > > Test the Action in the **Preview** beside the editor, or in the [Playground](/docs/user-guides/chatbot/playground). Both use your draft, so you can try it before you publish. ## Example: check a delivery area A `Check_delivery_area` Action that tells customers which suburbs a postcode covers, using the free Zippopotam postcode API. * **General:** named `Check_delivery_area`, with a **When to use** that covers questions about delivery areas and postcodes. * **Action type:** **Call API**. * **API:** one data input, `postcode`, of type **text**, described as the customer's 4-digit Australian postcode. The request is `GET https://api.zippopotam.us/au/{{postcode}}`. * **Test response:** **Live response** with `2000` as the postcode returns the Sydney suburbs. * **Data access:** **Full data access**. ![The bottom of the Channels section with the pointer on Save.](annotated/14-save.webp "Save stores the Action in your draft.") Now the agent can answer delivery-area questions: ![In the Preview chat, the customer asks whether we deliver to postcode 2010 and the agent replies with the suburbs that postcode covers, taken from the API.](walkthroughs/custom-action-chat.gif) ## How the AI agent handles the response * **Success:** the response, filtered by [Data access](#data-access), goes to the agent, which writes its reply from it. * **Not JSON:** a successful response that isn't JSON is passed to the agent as an error. * **Too large:** if the response is over 20 KB, the agent gets "Response is too large. Please limit the number of fields returned." * **Error or no answer:** the agent gets an error and writes its own reply. Failed requests aren't retried. The agent doesn't ask the customer to confirm before it calls the Action. For Actions that change data, such as cancelling a booking, tell it in **When to use** to confirm the details with the customer first. ## Limitations * **The maximum response size is 20 KB.** Use **Limited data access** or return fewer fields to stay under it. * **Requests and responses must be JSON.** * **No retries.** A failed request isn't sent again. * **Static authentication only.** Headers and parameters only, with no OAuth or token refresh. * **Client-side and widget types work on fewer channels.** **Run client-side code** works on the Chat bubble, Help page, Center Stage and the mobile SDKs. **Call API + show widget** and **Show widget** work on the Chat bubble, Help page and Center Stage. ## Best practices > [card] Clear Action triggers | /docs/user-guides/chatbot/actions/actions-overview | Name the data this Action provides and the questions it answers in When to use. > [card] Describe every input | /docs/user-guides/chatbot/playground | The description is how the agent decides what to ask for. Vague descriptions produce wrong values. > [card] Limit data access | /docs/user-guides/chatbot/guardrails | Use Limited data access when the response holds anything the agent shouldn't repeat. > [card] Keep responses small | /docs/developer-guides/widgets/overview | Return only the fields the agent needs to stay under 20 KB and keep replies accurate. ## Frequently asked questions > [accordion] How do I authenticate a Custom action with my API? > > Add your API key or token as a static header, for example `Authorization: Bearer `, or as a parameter. OAuth flows and token refresh aren't supported. > [accordion] Can I pass the customer's email or the conversation ID to my API? > > Yes. Use `{{contact.email}}`, `{{conversationId}}` and the other [variables](#variables) in the URL, parameters, headers or body. > [accordion] What happens when my API returns an error? > > The agent gets an error instead of data and writes its own reply to the customer. The request isn't retried. > [accordion] Can a Custom action run on WhatsApp, email or phone calls? > > Only the **Call API** type. The other types need the Chat bubble, Help page or Center Stage, and **Run client-side code** also runs in the mobile SDKs. > [accordion] Does the AI agent ask the customer before calling the API? > > No. It calls the Action as soon as it decides to. To require a confirmation, for example before a refund, say so in **When to use**. > [accordion] My response is over 20 KB. What can I do? > > Switch to **Limited data access** and tick only the fields the agent needs, or return fewer fields from your endpoint. ## Next steps > [card] Widgets | /docs/developer-guides/widgets/overview | Show your API data in an interactive widget. > [card] Client-side actions | /docs/developer-guides/website-integration/client-side-custom-actions | Run code on your website from the chat. > [card] Procedures | /docs/user-guides/chatbot/procedures/procedures-overview | Use Custom actions as steps in a flow. > [card] Backstage | /docs/user-guides/chatbot/backstage | Let Backstage build and test the Action for you. > [card] Tests | /docs/user-guides/chatbot/tests | Check the agent keeps calling the right Action.