# Call your own API from chat

> Let your agent call your own HTTPS endpoint mid-chat, for stock checks, returns or CRM updates, and answer from your reply. Business plan and up.

A custom action lets your agent call your own HTTPS endpoint in the middle of a conversation with details it collected, then answer from your reply. Use it for any system AskVault does not connect to directly. 

You set the URL, the HTTP method, an auth header and the fields the agent should fill in.

## Good fits

- A CRM or help desk AskVault does not connect to. Your endpoint calls its API.
- Home-grown inventory, returns or order systems.
- Order status for a store that is not on Shopify or WooCommerce.
- Triggering a Zapier or Make scenario.

## Before you start

- Business plan or up.
- An HTTPS endpoint that answers within a few seconds and returns JSON.
- Up to 10 custom actions per agent.

## Steps

#### New dashboard

1. Open **Behaviour** under **Your agent**, then **Actions**.
2. Under **More**, open **Custom actions** and add one.
3. Fill in the fields below, switch it on and save.

#### Previous dashboard

1. Open **Automation** › **Skills** and click **Custom actions**.
2. Add an action and fill in the fields below.
3. Switch the action on and save.

| Field | What to enter |
| --- | --- |
| **Name** | A short name for the action. |
| **Method** | GET, POST, PUT, PATCH or DELETE. |
| **Description (when the AI should use it)** | Say plainly when to use it. This is how the agent decides. There are no trigger phrases. |
| **Endpoint URL** | Where AskVault sends the call. |
| **Parameters** | The fields the agent fills in: a name, a type and whether it is required. |
| **Auth header** and **Auth value** | Optional. One custom header, for example `Authorization` with a Bearer token. The value is stored encrypted. |
| **Enabled** | Off until you switch it on. |

## What your endpoint receives

For POST, PUT and PATCH, AskVault sends exactly the parameters as a JSON body. For GET and DELETE it sends them as a query string such as `?sku=A12`, after any query string already in your URL. There is no fixed envelope around them.

A schema with the fields `ticket_subject`, `priority` and `customer_email` produces:

```json
{
  "ticket_subject": "Can't log in to my account",
  "priority": "high",
  "customer_email": "jane@example.com"
}
```

## What your endpoint returns

Return HTTP 200 with a JSON body that describes what happened. The agent reads it and writes its own reply, so keep it self-explanatory: a status, any ID the customer would want, and a short message. A status of 400 or above makes the agent say something generic and offer a person.

Example for a stock check:

```js
app.post('/stock', express.json(), async (req, res) => {
  if (req.get('Authorization') !== `Bearer ${process.env.STOCK_TOKEN}`) {
    return res.status(401).end();
  }
  const { sku } = req.body;
  const qty = await inventory.count(sku);
  res.json({ sku, in_stock: qty > 0, quantity: qty });
});
```

## Customer confirmation

An action that changes something, which is any method other than GET, shows the customer a confirmation card first, such as "I'll apply Create order (order_id=1042). Proceed?". It runs only after the customer's own yes in a later message. A confirmation the AI writes for itself is ignored. A GET action runs without a card.

## Security

The action authenticates with the header you configure. Check that header on your server and reject anything without it. Rotate the value if you suspect it leaked.

### Signed requests and verified identity (rolling out)

When request signing is on for your workspace, the action editor shows a **Signing secret** (owners and admins only, hidden until you click Reveal), and every action request carries two extra headers:

- `X-AskVault-Timestamp`: Unix seconds when the request was sent.
- `X-AskVault-Signature`: `sha256=` followed by the HMAC-SHA256 of `timestamp + "." + raw_body`, keyed with your signing secret. This is the same scheme as AskVault's event [webhooks](/developers/webhooks/), but the secret is a different one.

For POST, PUT and PATCH the JSON body also carries a reserved `askvault` object next to your parameters:

```json
{
  "order_id": "1042",
  "askvault": {
    "identity_verified": true,
    "identity_customer_id": "jane@example.com",
    "identity_email": "jane@example.com",
    "workspace_id": "ws_123",
    "conversation_id": "conv_456",
    "timestamp": 1763640000
  }
}
```

`identity_customer_id` and `identity_email` appear only when `identity_verified` is `true`, which means the visitor's widget session passed [identity verification](/developers/identity-verification/) (the user ID you signed). `identity_email` is present only when the ID you signed is an email address. The email a visitor types in chat is never put here. For GET and DELETE, which have no body, the same object is sent as JSON in the `X-AskVault-Context` header, and the signature covers that header's value instead of a body. The query string itself is not signed, so treat GET and DELETE parameters as untrusted input and act only on the signed identity. A signed request never follows a redirect to a different host: point the action at the final URL.

The AI fills in your parameters from the conversation, so a visitor can make it send any email or customer ID they like. **Trust `askvault.identity_*`, never a model parameter such as `customer_email`, for anything that touches a customer's account.** Parameters named `askvault`, `identity_verified`, `identity_email` or `identity_customer_id` are removed before the request is sent, so the AI cannot fake them.

Verify the signature on the raw bytes, before parsing, and reject requests older than five minutes:

```python

def verify(raw_body: bytes, secret: str, timestamp: str, signature: str) -> bool:
    if abs(time.time() - int(timestamp)) > 300:
        return False
    expected = hmac.new(secret.encode(), f"{timestamp}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(f"sha256={expected}", signature)

# Flask: verify(request.get_data(), SECRET, request.headers["X-AskVault-Timestamp"],
#               request.headers["X-AskVault-Signature"])
# GET/DELETE: pass request.headers["X-AskVault-Context"].encode() as raw_body.
```

```js
const crypto = require('crypto');

function verify(rawBody, secret, timestamp, signature) {
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  const expected = 'sha256=' + crypto.createHmac('sha256', secret)
    .update(`${timestamp}.`).update(rawBody).digest('hex');
  const a = Buffer.from(expected), b = Buffer.from(signature || '');
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

app.post('/refund', express.raw({ type: 'application/json' }), (req, res) => {
  if (!verify(req.body, process.env.ASKVAULT_SIGNING_SECRET,
              req.get('X-AskVault-Timestamp'), req.get('X-AskVault-Signature'))) {
    return res.status(401).end();
  }
  const { askvault, order_id } = JSON.parse(req.body);
  if (!askvault.identity_verified) return res.status(403).json({ error: 'sign in first' });
  // act for askvault.identity_customer_id, never for a parameter the AI filled in
});
```

## Limits

- **Timeout.** 15 seconds per attempt. The visitor is waiting, so aim to answer in a second or two.
- **Retries.** A 5xx response or timeout is retried up to 2 more times by default. A 4xx is never retried. `max_retries` takes 0 to 2 per action, and 0 means one attempt.
- **Rate.** Up to 60 calls per agent per hour. Hitting it gives the customer a polite fallback.
- **Slow work.** For jobs over about 10 seconds, reply at once that the work started, finish in the background, and tell the customer another way, such as email.

Turn on dry run while you test an endpoint that changes data.

## Check it worked

Ask your agent a question that should need the action in the [test chat](/agent/test-chat/). Check your endpoint's logs for the call and that the reply uses your data. Add that question to a [test suite](/agent/test-suites/) with the expected behaviour **Use an action**.

## If it doesn't work

**The action never fires.** The agent sees no reason to call it. Make the description say plainly when to use it, and check the action is on.

**Your auth check fails.** The header value differs between AskVault and your server. Re-copy it.

**The agent gives a generic error.** Your endpoint returned an error status or timed out. Check its logs.

**The reply reads oddly.** Make the JSON you return clearer.

## Related

- [Actions](/actions/)
- [Webhooks](/developers/webhooks/)
- [Developers](/developers/)

Source: https://docs.askvault.co/actions/call-your-api/
