# Zapier

> Call Curva from a Zapier Zap to route, tag or triage forms, emails, tickets and CRM records, then branch on the typed, calibrated answer.

Source: https://docs.tarkova.com/curva/guides/zapier/

Call Curva from a Zap to route, tag or triage anything a trigger brings in (a form, an email, a
ticket, a CRM record), then branch on the typed answer.

:::note[Generic HTTP, no official app yet]
There is no Curva app in the Zapier marketplace yet. This guide uses Zapier's built-in
**Webhooks by Zapier** app (a premium app, on paid plans) to call the
[HTTP API](/curva/reference/http-api/) directly. Your Curva server must be reachable from the
internet (see [Self-hosting](/curva/self-hosting/)) and should have an API key.
:::

## 1. Build the request body

Text from a trigger can hold quotes and newlines, which break JSON typed by hand. Add a
**Code by Zapier → Run JavaScript** step that builds the body, with the trigger fields as input
data (here `subject` and `body`):

```javascript
const request = {
  project: "support",
  state: { subject: inputData.subject, body: inputData.body },
  questions: {
    department: {
      type: "choice",
      instructions: "Which team should handle this",
      options: { billing: "Payments, refunds", technical: "Bugs", sales: "Pricing" },
      min_confidence: 0.8
    },
    refund: { type: "noul", instructions: "The customer explicitly asks for a refund" }
  }
};
return { json: JSON.stringify(request) };
```

## 2. Call `/v1/decide`

Add **Webhooks by Zapier → Custom Request**:

| Field | Value |
|---|---|
| Method | `POST` |
| URL | `https://curva.example.com/v1/decide` |
| Data | the `json` output of step 1 |
| Headers | `Content-Type` = `application/json`, `Authorization` = `Bearer curva_…` |

Zapier flattens the JSON response into fields such as **Answers Department Choice**,
**Answers Department Confidence**, **Answers Department Abstain**, **Answers Refund Noul** and
**ID**. Test the step once so later steps can map them.

## 3. Route on the answer

Add **Paths by Zapier**:

| Path | Rule |
|---|---|
| Human review | **Answers Department Abstain** (Boolean) is true |
| Billing | **Answers Department Choice** (Text) exactly matches `billing` |
| Technical | **Answers Department Choice** (Text) exactly matches `technical` |

Put the abstain path first, so an unsure answer never auto-routes. It gets `abstain: true`
because the question set `min_confidence`; create a task for a person there (a Slack message, an
Asana or Trello card, a helpdesk assignment). A Noul is a probability: route on
**Answers Refund Noul** (Number) greater than, say, `0.9`.

Keep **ID** (the decision id, `dec_…`) with the record you create, for step 4.

## 4. Send feedback

When the true answer is known (an agent reassigns the ticket, a reviewer closes the task), a
second Zap sends it back with another **Custom Request**, `POST` to
`https://curva.example.com/v1/feedback` with the same headers and data:

```json
{"decision_id": "dec_…", "question": "department", "label": "billing"}
```

From 30 labels for a question, its answers are calibrated whenever that makes them more accurate. See
[Calibrate with feedback](/curva/guides/feedback/).

## Check an action or screen a text

The same **Custom Request** to `/v1/decide` checks an action before a later step takes it, or
screens an email or form text before an AI step reads it. Build the body in the Code step:

```javascript
const check = { ask: "check", state: { action: { tool: "refund", amount: inputData.amount }, policy: "Refunds above $200 need a manager's approval." } };
const screen = { ask: "guard", state: inputData.body };
return { check: JSON.stringify(check), screen: JSON.stringify(screen) };
```

Route with **Paths by Zapier**, the unsure path first: for the check, **Answers Check Abstain**
is true → a person, then **Answers Check Choice** is `allow` or `block`; for the screen,
**Answers Verdict Abstain** is true or **Answers Verdict Choice** is `review` → a person,
`block` → stop. The fields and the default policy are in
[Check an action or screen a text](/curva/guides/any-http-tool/#check-an-action-or-screen-a-text).

## Errors and retries

Curva errors are JSON (`{"error": {"type", "message"}}`) with a 4xx or 5xx status, which fails
the Zapier step. A `429` carries `Retry-After`; turn on Zapier's autoreplay to retry it. The full
list is in the [HTTP API reference](/curva/reference/http-api/#errors).
