> ## Documentation Index
> Fetch the complete documentation index at: https://docs.impresivai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Triggers

> Set up webhook and polling trigger logic

# Triggers

In step 3, click **Add Trigger** and fill:

* **Label**
* **Description**
* **Type**: `Webhook` or `Polling`

## Trigger editors

Depending on trigger type, you will see tabs such as:

* **Parameters**
* **Subscribe (JS)**
* **Unsubscribe (JS)**
* **Handler (JS)**
* **Poller**
* **Sample Outputs (json)**

Use **Sample Outputs (json)** to define the payload shape passed to later steps.

## Webhook trigger pattern

* `Subscribe (JS)`: register remote webhook
* `Unsubscribe (JS)`: clean up registration
* `Handler (JS)`: normalize incoming payload before output

## Polling trigger pattern

Polling should return data only when a new item exists.

```js theme={null}
const category = parameters.category || 'all';
const key = `latestMarketId_${category}`;

// Example: fetch latest items from API
const res = await fetch('https://example.com/markets');
const markets = await res.json();
if (!markets?.length) return false;

const latest = String(markets[0].id);
const previous = await getValue(key);
await setValue(key, latest);

if (latest !== previous && previous) {
  return markets[0];
}

return false;
```

## Validate in Preview

* Use **Listen** for webhook testing
* Provide parameter values (for example `category`)
* Check **Outputs** and **Logs** before publishing
