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

# Price watch

> T1 starter · e-commerce: a price-drop alert with zero model calls.

> **T1 starter · e-commerce / personal**: no `infer:` anywhere in this
> file. A workflow engine is not an LLM wrapper: the DAG, the tools and
> one CEL comparison do the whole job, deterministically, for free.

## The job

You're waiting for a price to drop. Checking the page every day is a
robot's job. This workflow pulls one structured field from the shop's
API, compares it to your target, and pings your webhook only when it's
time to buy.

## The shape

```mermaid theme={"system"}
flowchart LR
  check["check · nika:fetch"]:::invoke
  alert["alert · nika:notify"]:::invoke
  check --> alert
  classDef invoke fill:#22d3ee22,stroke:#22d3ee,color:#22d3ee
```

## The file

```yaml price-watch.nika theme={"system"}
nika: price-watch

const:
  product_api: "https://api.shop.example.com/v1/products/macbook-air"
  alert_below: 899

secrets:
  alerts_webhook:
    source: env
    key: ALERTS_WEBHOOK_URL
    egress:                       # sanction the one send · the secret IS the URL
      - to: "nika:notify"
        host_from_self: true
permits:
  tools: ["nika:fetch", "nika:notify"]
  net:
    # TWO hosts, for two different reasons.
    #
    # `api.shop.example.com` is what `const.product_api` names — a literal
    # `check` can read, so a mismatch here is caught before the run.
    #
    # `hooks.slack.com` is the ALERT host, and it is the entry people leave
    # out. `host_from_self:` above sanctions the FLOW (this secret may be the
    # URL) — it does not grant the capability. The host stays unknown at
    # check, so it is judged at RUN against this bound: name the escalation
    # host here or the send is refused mid-run, the first time the price
    # actually drops. Swap it for wherever YOUR webhook lives.
    http: ["api.shop.example.com", "hooks.slack.com"]

tasks:
  check:
    invoke:
      tool: "nika:fetch"
      args:
        url: "${{ const.product_api }}"
        mode: jq
        jq: "."
    extract:                           # named jq bindings over the raw response
      price: ".price"
      name: ".name"
    on_error:
      # Rehearsal stand-in · the placeholder host resolves nowhere, so this
      # sample ABOVE the target takes over: the gate below stays closed and
      # the dry run ends green with the alert skipped. The alert path is
      # therefore NOT exercised by the rehearsal — which is exactly why the
      # `net:` bound above has to be right by reading, not by running.
      recover: { price: 949, name: "MacBook Air (rehearsal sample)" }

  alert:
    with:
      price: ${{ tasks.check.price }}     # value edges · the named bindings cross the boundary here
      name: ${{ tasks.check.name }}
    when: ${{ with.price < const.alert_below }}
    invoke:
      tool: "nika:notify"
      args:
        channel: webhook
        target: "${{ secrets.alerts_webhook }}"
        message: "Price drop · ${{ with.name }} is now ${{ with.price }} (target ${{ const.alert_below }})"
        severity: info

outputs:
  price: ${{ tasks.check.price }}
```

## How it works

**1. Fetch ONE field, not a page**

`mode: jq` extracts structured JSON from the API response, and the
`extract:` block binds named fields: `${{ tasks.check.price }}` is a
number, not a blob of HTML.

**2. CEL gates the alert**

The named binding crosses in `with:`
(`price: ${{ tasks.check.price }}`), then
`when: ${{ with.price < const.alert_below }}` is a plain CEL
comparison. False → the task is skipped, not failed.

**3. The webhook stays secret**

`secrets:` declares an env-backed reference (`source: env`; `file` is
the other store 0.124.3 resolves). A `vault` source is withdrawn from the
contract: the check stays green with a hint that names `NIKA-VAR-001`,
and the run fails with it, an unresolved `secrets.<name>`. The URL is
masked in logs: `${{ secrets.alerts_webhook }}` never appears in a trace.

## Constructs you just used

| Construct | Where | Reference |
| - | - | - |
| `nika:fetch` `mode: jq` | `check` | [Builtins](https://docs.nika.sh/reference/builtins.md) |
| `extract:` jq bindings | `check.price` | [Bindings](https://docs.nika.sh/concepts/bindings.md) |
| `when:` CEL comparison | `alert` | [Workflows](https://docs.nika.sh/concepts/workflows.md) |
| `secrets:` | envelope | [YAML syntax](https://docs.nika.sh/reference/yaml-syntax.md) |

## Run it

> [!NOTE]
>
> **What it needs:** Nothing: the placeholder shop host resolves nowhere, and the `recover:` sample sits above the target, so the alert is skipped. No model, no key.

**1. Rehearse it**

```bash theme={"system"}
nika try price-watch
```

Nothing is written in your folder. Before it runs, `nika try` names the hosts a step may reach: `may reach: api.shop.example.com · hooks.slack.com — the mock replaces the model, not the network`.

**2. Get your own copy**

Save the file above as `price-watch.nika` in a new folder. It reads no sample file.

**3. Check it, then run it**

```bash theme={"system"}
nika check price-watch.nika
nika run price-watch.nika
```

The run writes no file: it pings your webhook only when the price drops below the target.

To watch a real product, point `const.product_api` at it, add its host to `permits.net.http`, and set `ALERTS_WEBHOOK_URL`.

## Make it yours

* Watch N products: lift the URL into a list input and `for_each` over it. See [Competitor radar](https://docs.nika.sh/examples/competitor-radar.md) for the fan-out pattern.
* Schedule it: workflow files describe a run. Your host's cron (or `nika serve`) decides when runs start.
* Add a second `when:` branch that notifies on price INCREASES above a ceiling.

> [card] [Next · Social repurpose](https://docs.nika.sh/examples/social-repurpose.md)
>
> The last starter introduces the diamond: one source fanning into
> three parallel rewrites.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.