> For the complete documentation index, see [llms.txt](https://docs.perkville.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.perkville.com/features/redeeming-rules/using-middle-to-automate-rewards/real-time-redemption-requests.md). Agents can also search and read this documentation through its [MCP server](https://docs.perkville.com/~gitbook/mcp).

# Real-time redemption requests

When a reward is configured to use Middle, Perkville sends its redemption and member details to the selected workflow as a JSON webhook request. The request runs synchronously: Perkville waits for the workflow result and uses it to decide how to complete the redemption.

Follow [Using Middle to automate rewards](https://docs.perkville.com/features/redeeming-rules/using-middle-to-automate-rewards.md) to connect the reward. See [Real-time redemption responses](https://docs.perkville.com/features/redeeming-rules/using-middle-to-automate-rewards/real-time-redemption-responses.md) for the required output and point deduction rules.

## When the request is sent

Perkville sends the request while fulfilling a reward with Middle automation enabled. Both the business’s Middle API key and the reward’s selected workflow URL must be configured. If either is missing, Perkville rejects the redemption before sending the request.

For ordinary points redemptions, the request occurs while Perkville’s redemption transaction is still open. The response can cause that transaction to commit or roll back. Configured instant rewards use the same request format. Automatic challenge rewards can defer fulfillment until after their reward transaction is committed; see [Automatic challenge rewards](https://docs.perkville.com/features/redeeming-rules/using-middle-to-automate-rewards/real-time-redemption-responses.md#automatic-challenge-rewards).

## Endpoint and authentication

| Setting                    | Value                                                                                                             |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| Method                     | `POST`                                                                                                            |
| URL                        | The invoke URL selected for the reward, normally `https://perkville.middle.app/api/workflow-invoke/{path_token}/` |
| Authorization              | `Authorization: Bearer <business Middle API key>`                                                                 |
| Content type               | `application/json`                                                                                                |
| Body                       | A JSON object with the fields below                                                                               |
| Default request timeout    | 25 seconds                                                                                                        |
| Automatic delivery retries | The Perkville redemption request helper does not automatically retry the POST.                                    |

The body is sent directly, with no outer `data` object or event envelope. Middle’s request size limit is 256 KiB. The invoke URL is generated by Middle; use the selected URL rather than constructing a path token.

## Example request

The values below are illustrative.

```json
{
  "transaction_id": 987654321,
  "user_email": "member@example.com",
  "perk_id": 410,
  "perk_title": "Free smoothie",
  "business_id": 100,
  "business_name": "Example Fitness",
  "location_id": 200,
  "external_location_id": "club-001",
  "location_name": "Downtown",
  "user_first_name": "Alex",
  "user_last_name": "Morgan",
  "ext_member_id": "member-123",
  "external_membership_status": "ACTIVE",
  "ext_membership_type": "Gold",
  "external_member": [
    {
      "external_system_id": "MINDBODY",
      "external_member_id": "member-123",
      "external_membership_type": "Gold",
      "external_membership_status": "ACTIVE",
      "external_join_dt": "2026-01-15T10:00:00+00:00",
      "external_cancel_dt": null,
      "home_location_id": 200,
      "external_home_location_id": "club-001",
      "home_location_name": "Downtown"
    }
  ]
}
```

## Top level fields

| Field                        | Meaning                                                                                                                                       |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `transaction_id`             | Perkville transaction primary key; JSON number.                                                                                               |
| `user_email`                 | The user’s primary email address.                                                                                                             |
| `perk_id`                    | Perkville reward ID; JSON number.                                                                                                             |
| `perk_title`                 | Reward title captured on the transaction.                                                                                                     |
| `business_id`                | Perkville business ID; JSON number.                                                                                                           |
| `business_name`              | Business name.                                                                                                                                |
| `location_id`                | Perkville redemption location ID; JSON number.                                                                                                |
| `external_location_id`       | Redemption location’s ID in the external system.                                                                                              |
| `location_name`              | Redemption location name.                                                                                                                     |
| `user_first_name`            | User’s first name.                                                                                                                            |
| `user_last_name`             | User’s last name.                                                                                                                             |
| `ext_member_id`              | Member ID selected on the user’s business connection; `null` if there is no connection.                                                       |
| `external_membership_status` | Membership status on that business connection; `null` if there is no connection.                                                              |
| `ext_membership_type`        | Membership type on that business connection; `null` if there is no connection.                                                                |
| `external_member`            | Array of external membership records for this user and business; `[]` when none exist. The key is singular even though the value is an array. |

All 15 keys are included in each request. Optional source values can be null or blank. The payload does not include points, quantity, voucher ID, voucher code, a redemption timestamp, or a separate event name.

## External member fields

`external_member` is an array, despite its singular name. It includes all external membership records for this user and business, ordered by their Perkville record ID, including inactive memberships. If none exist, its value is `[]`. Select the relevant membership using `external_system_id` and the rules of your integration.

| Field in each array item     | Meaning                                                         |
| ---------------------------- | --------------------------------------------------------------- |
| `external_system_id`         | External system identifier, such as `MINDBODY`.                 |
| `external_member_id`         | Member ID in that system.                                       |
| `external_membership_type`   | Membership type, potentially null or blank.                     |
| `external_membership_status` | Membership status, such as `ACTIVE` or `INACTIVE`, or null.     |
| `external_join_dt`           | ISO 8601 datetime string, or null.                              |
| `external_cancel_dt`         | ISO 8601 datetime string, or null.                              |
| `home_location_id`           | Perkville ID of the membership’s active home location, or null. |
| `external_home_location_id`  | External ID of that home location, or null.                     |
| `home_location_name`         | Name of that home location, or null.                            |

The three home location fields are null when the member’s home location is missing or inactive. These fields describe that membership’s home location. The top level `location_id`, `external_location_id`, and `location_name` describe the redemption location.

## Configure the workflow inputs

Define each top level payload key that the workflow needs on its Begin step. Middle passes declared keys into the workflow, ignores undeclared keys with a warning, and supplies null for missing declared keys. Discovery metadata describes intended types, but Middle does not validate every input value against those types before execution.

Handle null membership details and an empty `external_member` array explicitly. When several external memberships exist, select the intended system and member before applying the reward.

Perkville discovers available endpoints through `GET /api/workflow-invoke-options/` using the business’s Bearer key. The reward selector offers workflows whose output schema includes boolean `success` and string `success_message` and `error_message`. This compatibility check covers the output schema; configure the inputs to match this request.

See the [Middle Real-time Workflow API](https://docs.middle.app/middle-docs/product/real-time-workflow-api) for endpoint setup, API key access, input handling, and limits.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.perkville.com/features/redeeming-rules/using-middle-to-automate-rewards/real-time-redemption-requests.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
