# Template: a ready grant becomes credit

When a reward that is not cash is ready, give the credit in your own tool and mark it fulfilled.

A template for Make or n8n that gives a reward of credit in your own tool the
moment Bolt Claw says it is ready, then tells Bolt Claw it was given. It is
for a [reward that is not cash](https://boltclaw.ai/docs/rewards-not-cash) of the kind **credit**,
given to one of your own users: a referrer you made, or the friend who bought.

## What it does

1. Bolt Claw sends `referral.grant.ready` when a grant finishes the program's
   hold. The template checks the delivery's signature and time first, and does
   nothing else with one that fails.
2. It reads the grant with `GET /v1/referrals/grants/{id}`: what it is now, not
   what the delivery said.
3. Only when the grant is `ready`, its `reward_type` is `credit` and it belongs
   to one of your own users (`recipient.kind` `referrer` or `customer`, with your
   `external_id`), it asks your tool to give the credit.
4. Then it records it with `POST /v1/referrals/grants/{id}/fulfil` and the
   reference `credit-<grant id>`. The person sees the reward as given on their
   page, and Bolt Claw sends `referral.grant.fulfilled`.

Every other grant (a free month, a perk, an affiliate's reward) stays ready on
the program's **Grants** tab for you to give.

## What your tool receives

A `POST` to the address you put in **Give the credit**, with your tool's own
key, and the header `Idempotency-Key: boltclaw-grant-<grant id>`:

| Field | Example |
|---|---|
| `user_id` | `user-1042`: your own id for the person |
| `amount_minor` | `1000` |
| `currency` | `USD` |
| `description` | `10.00 USD in credit` |
| `boltclaw_grant_id` | the grant's id |
| `test` | `true` for a grant from test data: give nothing |

n8n sends it as JSON; Make sends it as form fields. **Give the credit once per
`Idempotency-Key`.** That is what makes a repeat safe: if the step runs twice,
the second must find the first and change nothing.

## Before you start

- A key with `referrals:read` and `referrals:write`, made by somebody who
  holds **Adjust commissions and pay partners** (owners and admins do by
  default): marking a grant given is a payout decision.
- An endpoint in **Settings, Developers, Webhooks** for the event
  `referral.grant.ready`, added once you have the template's address. Copy its
  signing secret: it is shown once.

## In Make

1. Download `https://boltclaw.ai/referrals/templates/make/grant-ready-to-credit.json` and import it (**...** menu, **Import
   Blueprint**).
2. In the first module, **Add** a webhook. Under **Show advanced settings**, set
   **Get request headers** and **JSON pass-through** to **Yes**. Copy its
   address and add it as the endpoint in Bolt Claw.
3. **Expected signature**: replace `PASTE_THE_ENDPOINT_SIGNING_SECRET` with the
   signing secret. Keep the quotes.
4. **Read the grant** and **Mark the grant fulfilled**: replace
   `bc_live_PASTE_YOUR_KEY` in the `Authorization` header.
5. **Give the credit in your tool**: your tool's address, its key, and the
   field names it expects.
6. Switch the scenario on.

Each call retries three times, 15 minutes apart, before the run is kept as an
incomplete execution for you to look at.

## In n8n

1. Download `https://boltclaw.ai/referrals/templates/n8n/grant-ready-to-credit.json` and import it (**Import from File**).
2. **Verify signature**: put the signing secret in an n8n Variable
   `BOLTCLAW_WEBHOOK_SECRET`, or between the quotes at the top of the node.
3. **Read the grant** and **Mark the grant fulfilled**: a **Header Auth**
   credential, Name `Authorization`, Value `Bearer bc_live_...`.
4. **Give the credit**: your tool's address and its own credential.
5. Publish the workflow and add the **Bolt Claw webhook** node's production
   address as the endpoint.

## Test it

- **The signature.** Press **Test** on the endpoint in **Settings, Developers,
  Webhooks**. The test event passes the signature check and stops at the event
  check (Make: the **Only referral.grant.ready** filter; n8n: **Grant ready
  event?**). That is the result you want: the secret is right.
- **A grant.** Switch on **Also send test events** for the endpoint, and in a
  program that gives credit, press **Send a test sale** on its **Setup** tab.
  The test grant waits out the program's hold like a real one; when it is
  ready, the delivery arrives with `test` set, and your tool should give
  nothing.

## When something goes wrong

- **Your tool failed.** Nothing was recorded in Bolt Claw, so the grant is
  still `ready`: retry the run, or give it on the **Grants** tab.
- **Bolt Claw answered `409` to the fulfil.** The grant is no longer ready:
  usually its sale was refunded or disputed and the grant was cancelled. Take
  the credit back in your tool if your own terms allow.
- **Bolt Claw answered `428`.** The key belongs to an AI assistant, and a person
  must approve marking a grant given. Use a key a person made instead.

<!-- https://boltclaw.ai/docs/referral-template-grant-credit as markdown. Generated from openapi.yaml; API version 1.22.0. -->
<!-- Every /docs page answers as markdown: add .md to its path, or send Accept: text/markdown. -->
