# JavaScript API

> For order pages that send the order with fetch or AJAX instead of submitting a form.

This is one page of the Antiro docs (https://docs.antiro.io/sdk/javascript). Every page in one file: https://docs.antiro.io/llms-full.txt

> **You may not need this**
>
> If your order button is a submit button of the order form, the script already covers it, even when your own code sends the order.

## Check an order before sending it

Call `Antiro.decide()` when the shopper presses the order button, and send its `token` with the order. The script may not have loaded, so check for it first and send the order anyway: your server check still runs.

**An order page that sends with JavaScript**

```js
async function placeOrder(order) {
  const check = window.Antiro
    ? await window.Antiro.decide({
        phone: order.phone,
        name: order.name,
        address: order.address,
      })
    : { act: 'allow', token: '' };

  // notice or block: the shopper saw a message
  if (check.act !== 'allow') return;

  await fetch('/api/orders', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      ...order,
      session_token: check.token,
    }),
  });
}
```

## What decide returns

`Antiro.decide()` resolves to `{ act, token }`:

| `act` | Meaning | What to do |
| --- | --- | --- |
| `allow` | The order can go. Also returned on any failure. | Send the order, with `token` as `session_token`. |
| `notice` | The shopper was asked to change something on their side. | Do not send. Call `decide()` again at the next press. |
| `block` | The shopper saw the refusal message. | Do not send. |

## Reference

- `Antiro.decide(contact)` (Promise): Checks the order. `contact` holds `phone`, `name` and `address`, all optional. Each call runs one check, and a call made while a check is running shares its answer.
- `Antiro.token()` (string): The current order reference, to send as `session_token`.
- `Antiro.ready()` (Promise): Settles once the script has tried to start its session.
- `Antiro.verdict()` (string): `bot` when Antiro judged this tab automated, `ok` when it answered, otherwise `unknown`.
- `Antiro.version` (string): The script’s version.
