Custom action (HTTP request)
Connect your own API to the agent with a Custom action: define the HTTP request, map parameters from the conversation and use the response in replies.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
A Custom action sends an HTTP request to your own service when the agent needs live data or needs to change something. Use it for order lookups, account checks, booking changes or anything your systems know and the sources do not.
Create the action
- Open the agent and select Actions.
- Select Add action and choose Custom action.
- Name it, for example
Get order status. - Write the description: "Use this when the customer asks about an order and has given an order number."
- Choose the Method and enter the URL.
- Add headers, parameters and a body (see below).
- Select Test, then turn the action on and select Save.
Request settings
| Setting | Notes |
|---|---|
| Method | GET, POST, PUT, PATCH or DELETE. |
| URL | Your endpoint. Put parameters in with braces, such as https://shop.example.com/api/orders/{orderNumber}. |
| Headers | For example Authorization with a token. Header values are stored as secrets and hidden after saving. |
| Parameters | Each one has a name, a type and a description. The agent fills them in from the conversation. |
| Body | JSON template for POST, PUT and PATCH requests. |
A body template looks like this:
{
"orderNumber": "{orderNumber}",
"reason": "{reason}",
"requestedBy": "{contact.email}"
}
Values in braces come from the parameters you defined or from the contact. Describe each parameter well, because the agent uses the description to decide what to ask for.
Use the response
The agent reads the JSON your endpoint returns and writes the reply from it. Return short, plain fields, such as status, carrier and estimatedDelivery, rather than a large internal record. If a field holds a value in your own code, such as 3, add the meaning in a field the agent can read, such as statusLabel.
Test it
- Select Test in the action editor, fill in sample values and check the response.
- Open Test > Playground and trigger the action with a real question.
- Read the trace to see the request the agent sent and what came back.
You should see the status code and the response body in the trace.
Warning: Use a read-only or narrowly scoped token for the request. For actions that change data, add the rule to a procedure, for example "Only cancel an order that has not shipped."
Troubleshooting
- The agent never calls it. Improve the description and the parameter descriptions.
- The agent calls it with the wrong value. Add an example to the parameter description.
- You see a 401 or 403 in the trace. Check the header value and the token's access in your own system.
Related: Actions overview and Build actions with Backstage.