# Funnel decision HTTP reference

HTTP headers, JSON payloads, response statuses, and recovery for campaign_decide, read_decision, and report_used.

[Web version](https://www.longplayai.com/docs/api/funnel-decisions)

<a id="headers"></a>

## Endpoint and headers

All three operations are sent from your backend to the same endpoint. Angle brackets are template values; obtain the App UUID, Server Key, Funnel UUID, and user ID from real configuration and trusted identity.

**request.http**

```bash
POST https://api.longplayai.com/api/v1/funnels
Authorization: Bearer <SERVER_KEY>
Content-Type: application/json
X-Indiana-Project: <APP_UUID>
X-Indiana-Environment: sandbox
X-Indiana-Protocol: 0.10
```

**Operations in this path**

| operation | Success HTTP | Purpose |
| --- | --- | --- |
| campaign_decide | 200 or 202 | Accept a decision; 202 means processing continues |
| read_decision | 200 or 202 | Read an accepted decision by decisionId |
| report_used | 200 | Record caller-reported adoption |

Responses include X-Request-Id and Cache-Control: no-store. A 202 response includes Retry-After: 1. Send Prefer: respond-async to receive a pending status immediately.

<a id="decide"></a>

## Decide

Fill attributes with registered business facts verified by your backend. The empty object below only shows the request shape. customer may also be { type: "id", value: "<CUSTOMER_UUID>" }. For a missing externalUserId, optional customerData applies only when creating the Customer.

**decide.request.json**

```json
{
  "operation": "campaign_decide",
  "funnelId": "<PUBLISHED_FUNNEL_UUID>",
  "requestId": "<PERSISTED_REQUEST_UUID>",
  "customer": {
    "type": "externalUserId",
    "value": "<VERIFIED_USER_ID>"
  },
  "attributes": {}
}
```

Example completed response. The published Funnel defines the value and its data fields.

**decide.response.json**

```json
{
  "scope": {
    "projectId": "<APP_UUID>",
    "environment": "sandbox"
  },
  "decisionId": "<DECISION_UUID>",
  "requestId": "<PERSISTED_REQUEST_UUID>",
  "status": "completed",
  "decision": {
    "requestId": "<PERSISTED_REQUEST_UUID>",
    "decisionId": "<DECISION_UUID>",
    "customerId": "<CUSTOMER_UUID>",
    "externalUserId": "<VERIFIED_USER_ID>",
    "versionId": "<PUBLISHED_VERSION_UUID>",
    "receiptId": "<RECEIPT_UUID>",
    "value": {
      "type": "bundle",
      "data": {
        "recommendedPlan": "pro",
        "annualOffers": [{ "plan": "pro", "percentOff": 20 }]
      },
      "offering": null,
      "coupons": [],
      "paywall": null
    }
  }
}
```

For a 202 / pending response, retain decisionId and call read_decision on the same endpoint, or let the SDK poll. Reuse the original requestId when retrying.

**decide.pending.json**

```json
{
  "scope": { "projectId": "<APP_UUID>", "environment": "sandbox" },
  "decisionId": "<DECISION_UUID>",
  "requestId": "<PERSISTED_REQUEST_UUID>",
  "status": "pending",
  "decision": null
}
```

<a id="read-decision"></a>

## Read a pending decision

After receiving a decisionId with pending status, read it with the same Server Key, App, and environment. The response uses the same shape as the Decide responses above. Do not generate a new campaign_decide requestId.

**read-decision.request.json**

```json
{
  "operation": "read_decision",
  "decisionId": "<DECISION_UUID_FROM_DECIDE>"
}
```

<a id="report-used"></a>

## Adoption receipt: report_used

Use the decide decisionId. eventId is a persisted UUID for the adoption fact; occurredAt is the actual ISO 8601 occurrence time. Retry with the same eventId, occurrence time, and reference. This records a caller statement; it does not prove payment or issue a Coupon.

**receipt.request.json**

```json
{
  "operation": "report_used",
  "decisionId": "<DECISION_UUID_FROM_DECIDE>",
  "eventId": "<PERSISTED_EVENT_UUID>",
  "occurredAt": "<ACTUAL_TIME_ISO_8601>",
  "reference": "<ORDER_OR_SUBSCRIPTION_ID>"
}
```

**receipt.response.json**

```json
{
  "scope": { "projectId": "<APP_UUID>", "environment": "sandbox" },
  "decisionId": "<DECISION_UUID_FROM_DECIDE>",
  "eventId": "<PERSISTED_EVENT_UUID>",
  "source": "caller_reported"
}
```

<a id="recovery"></a>

## Errors and recovery

**What to check first**

| HTTP / code | Action |
| --- | --- |
| 400 / INVALID_REQUEST | Check operation, UUIDs, attributes, and JSON body. |
| 401 / UNAUTHENTICATED | Check that the Server Key is complete and valid, and that the request has no browser Origin. |
| 403 / FORBIDDEN | Check the Key's App/environment and customers:write, sessions:create, and funnels:run; Paywall or Offering steps also need entitlements:read, buying from a Paywall needs billing:read and billing:write, and Coupons need offers:resolve. |
| 409 / CONFLICT | A paused Funnel accepts no new decisions; show it as temporarily unavailable. Replaying the original requestId still returns the original result. |
| 202 / pending | Keep the decisionId and read the original decision after Retry-After. |

Error responses contain requestId and an error object. Follow error.code, retryable, and recovery, and retain X-Request-Id for support. When acceptance is unknown, retry the original requestId and complete input; do not create a second decision with a new ID.
