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

# How to Capture Data

### Capturing via WhatsApp

In Reportana's advanced automations and campaigns, it is possible to use WhatsApp messages to interact with customers and capture important data. The advanced options for WhatsApp messages allow you to validate customer responses and store them in specific variables for later use. These variables can be used within the **Run JavaScript** block, enabling the creation of more complex logic. See the example below:

<img src="https://mintcdn.com/reportana/cEIYEKOrJ1QXoaCs/cap-data2-en.png?fit=max&auto=format&n=cEIYEKOrJ1QXoaCs&q=85&s=3dfdb6779893692c66d5c51cf7d5535b" alt="Capturing with interaction" width="1731" height="731" data-path="cap-data2-en.png" />

<img src="https://mintcdn.com/reportana/cEIYEKOrJ1QXoaCs/cap-data3-en.png?fit=max&auto=format&n=cEIYEKOrJ1QXoaCs&q=85&s=f1a726522c04cd5616e426a18e0f7aad" alt="Capturing with interaction" width="817" height="723" data-path="cap-data3-en.png" />

<img src="https://mintcdn.com/reportana/cEIYEKOrJ1QXoaCs/cap-data4-en.png?fit=max&auto=format&n=cEIYEKOrJ1QXoaCs&q=85&s=de78215e85d70aca360795ffd72f4ce8" alt="Capturing with interaction" width="793" height="705" data-path="cap-data4-en.png" />

In this example, we define an interaction within the automation structure to capture the customer's responses, which are stored in the variables `payload.height` and `payload.weight`. These variables can later be used to calculate the BMI, as shown in the following example:

<img src="https://mintcdn.com/reportana/cEIYEKOrJ1QXoaCs/cap-data5-en.png?fit=max&auto=format&n=cEIYEKOrJ1QXoaCs&q=85&s=71722d4435a9bb5cd6a0257bf0327f07" alt="Capturing with payload" width="792" height="518" data-path="cap-data5-en.png" />

<RequestExample>
  ```javascript Example Code 1 theme={null}
  var height = payload.height / 100;

  var bmi = payload.weight / (height * height);

  if (bmi < 20) {
    payload.result = 'You are underweight!';
  } else if (bmi > 20 && bmi <= 25) {
    payload.result = 'Ideal Weight';
  } else if (bmi > 25 && bmi <= 30) {
    payload.result = 'Overweight';
  } else if (bmi > 30 && bmi <= 35) {
    payload.result = 'Moderate Obesity';
  } else if (bmi > 35 && bmi <= 40) {
    payload.result = 'Severe Obesity';
  } else if (bmi > 40 && bmi <= 50) {
    payload.result = 'Morbid Obesity';
  } else {
    payload.result = 'Result not defined';
  }
  ```
</RequestExample>

<ResponseExample>
  ```javascript Example Code 2 theme={null}
  var subscriptionValue = payload.response_json.users[0].subscriptionAmount;

  // Calculating the value with a 15% discount
  var discountedValue = subscriptionValue - subscriptionValue * 0.15;

  payload.discount = discountedValue.toFixed(2);
  ```
</ResponseExample>

To enhance understanding of data capture using WhatsApp messages, we recommend reading our article available in the Help Center: [Understanding the Logic, Time, Chat, and Advanced Actions in Automations](https://reportana.com/help/article/understanding-logic-time-chat-and-advanced-actions-automations)

### Capturing with Send Webhook

In advanced automations and campaigns, it is also possible to use the **Send Webhook** functionality to receive and capture data from other systems. This data can be integrated into automations, allowing, together with the use of **Execute JavaScript**, automations to be customized by creating dynamic experiences during customer interaction.

1. To configure data capture through **Send Webhook**, first you can define the URL of an external system and choose the desired request method.

<img src="https://mintcdn.com/reportana/rrUbVfAgCraOJwnY/webhook1-en.png?fit=max&auto=format&n=rrUbVfAgCraOJwnY&q=85&s=0343c2ba6e60d49964c6ca98d4f377de" alt="Example Send Webhook: image 1" width="1662" height="801" data-path="webhook1-en.png" />

2. For data capture, the received response can be stored in a specific variable, which can be used in subsequent automation steps. In the example, we chose `payload.response_json` as the variable that will store the information.

<img src="https://mintcdn.com/reportana/rrUbVfAgCraOJwnY/webhook2-en.png?fit=max&auto=format&n=rrUbVfAgCraOJwnY&q=85&s=c7fd636f85b701dd1a01c8f7d08ef697" alt="Example Send Webhook: image 2" width="839" height="502" data-path="webhook2-en.png" />

3. In the example, we receive the following data from a subscription in JSON format:

```json theme={null}
{
  "users": [
    {
      "name": "Mary Smith",
      "email": "mary.smith@example.com",
      "phone": "+1 555-123-4567",
      "plan": "Premium",
      "subscriptionValue": 149.99
    }
  ]
}
```

* Name: Name used in the subscription registration.
* Email: Email used in the subscription registration.
* Phone: Phone number used in the subscription registration.
* Plan: Active plan in the subscription.
* Subscription Value: The value of the respective subscription.

4. Next, in **Execute JavaScript**, we directly access the data captured by **Send Webhook** and create the code to provide the client, via WhatsApp, with the subscription value applying a 15% discount.

<img src="https://mintcdn.com/reportana/rrUbVfAgCraOJwnY/webhook3-en.png?fit=max&auto=format&n=rrUbVfAgCraOJwnY&q=85&s=6f6e877512b4e0863a7f3b3d2c863d60" alt="Example Send Webhook: image 3" width="793" height="317" data-path="webhook3-en.png" />

**Note:** In the code, we specifically access the property `payload.response_json.users[0].subscriptionValue` which corresponds to the current subscription value.

5. Finally, we use the result of the code saved in the variable `payload.discount` in the WhatsApp message that will be sent to the customer.

<img src="https://mintcdn.com/reportana/rrUbVfAgCraOJwnY/webhook4-en.png?fit=max&auto=format&n=rrUbVfAgCraOJwnY&q=85&s=9bb89e086710d96a415db530f5fe5746" alt="Example Send Webhook: image 4" width="784" height="295" data-path="webhook4-en.png" />
