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

# Data endpoint

> Serve dynamic data to WhatsApp Flows

Dynamic WhatsApp Flows call your data endpoint to fetch screen content at runtime.

## How it works

```mermaid theme={null}
sequenceDiagram
    participant User
    participant Meta
    participant Kapso
    participant Function as Your Function
    User->>Meta: Opens flow in WhatsApp
    Meta->>Kapso: Encrypted request
    Kapso->>Function: Decrypted payload
    Function->>Kapso: Screen data
    Kapso->>Meta: Encrypted response
    Meta->>User: Dynamic content
```

1. User opens the flow in WhatsApp
2. Meta sends an encrypted request to Kapso
3. Kapso decrypts and forwards to your function
4. Your function returns screen data
5. Kapso encrypts and returns to Meta
6. User sees the dynamic content

## Setup requirements

Before using data endpoints:

1. **WhatsApp phone number** - Set in the Info tab
2. **Flows encryption** - One-time setup per phone number (Kapso handles the key exchange)
3. **Function** - Your code that returns screen data

## Request format

Kapso sends this payload to your function:

```json theme={null}
{
  "source": "whatsapp_flow",
  "flow": {
    "id": "kapso_flow_id",
    "meta_flow_id": "meta_flow_id"
  },
  "data_exchange": {
    "version": "3.0",
    "action": "data_exchange",
    "screen": "CURRENT_SCREEN",
    "data": {},
    "flow_token": "unique_session_token"
  },
  "signature_valid": true,
  "received_at": "2024-01-15T10:30:00Z"
}
```

The `data_exchange` object contains Meta's original payload with the current screen and any user-submitted data.

## Response format

Your function must return:

```json theme={null}
{
  "version": "3.0",
  "screen": "NEXT_SCREEN_ID",
  "data": {
    "field_name": "value"
  }
}
```

| Field     | Description                                   |
| --------- | --------------------------------------------- |
| `version` | Always `"3.0"`                                |
| `screen`  | Screen ID to display next                     |
| `data`    | Key-value pairs matching screen's data schema |

### Completing the flow

To end the flow and close it:

```json theme={null}
{
  "version": "3.0",
  "screen": "SUCCESS",
  "data": {
    "extension_message_response": {
      "params": {
        "flow_token": "from_request"
      }
    }
  }
}
```

## Limits

| Limit            | Value                        |
| ---------------- | ---------------------------- |
| Response timeout | 15 seconds                   |
| Rate limit       | 100 requests/minute per flow |

## Error handling

If your function fails or times out, Kapso returns an error screen to the user. Check the **Invocations** in your function dashboard for debugging.
