# Fetch Campaign Messages Stats

## Fetch Campaign Messages

This **API** helps you to fetch the data of messages sent to the end-user **against a checkout/ order.**

{% hint style="info" %}
This API requires an active WhatsApp Account on QuickReply.ai
{% endhint %}

{% hint style="info" %}
Within a single response, the API returns **50 messages data** along with **an offset value** which can be reused to pull in the next batch of 50 messages.
{% endhint %}

## Fetch the Message Stats using an API

<mark style="color:green;">`POST`</mark> `https://cloudfunc.intelliticks.com/api/companyStats/fetchCampaignsData`

The body is a JSON Object

#### Query Parameters

| Name                                        | Type   | Description                                                                                                                                                                                                            |
| ------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| startTime<mark style="color:red;">\*</mark> | String | <p><strong>Starting time</strong> for the data to be fetched</p><p><em>Epoch Timestamp (milliseconds)</em></p>                                                                                                         |
| endTime<mark style="color:red;">\*</mark>   | String | <p><strong>End time</strong> for the data to be fetched</p><p><em>Epoch Timestamp (milliseconds)</em></p>                                                                                                              |
| offset                                      | String | <p>The API returns <strong>50 messages data</strong> within one response along with <strong>an offset value</strong> which can be reused to pull in the next batch of 50 messages.</p><p><em>Default value: 0</em></p> |

#### Headers

| Name                                         | Type   | Description                                                                                                                                     |
| -------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| client-id<mark style="color:red;">\*</mark>  | String | You can find client-id of your account in [Settings > Developers > API credentials](https://app.quickreply.ai/v2/settings/dev/api-credentials)  |
| secret-key<mark style="color:red;">\*</mark> | String | You can find secret-key of your account in [Settings > Developers > API credentials](https://app.quickreply.ai/v2/settings/dev/api-credentials) |

{% tabs %}
{% tab title="200: OK On Success" %}
{% code overflow="wrap" fullWidth="true" %}

```json
{
  "success": true,
  "message": "success",
  "data": [
    {
      "event_id": "25558457545622",
      "type": "Checkout",
      "data": [
        {
          "campaignId": "pouqDjkhjkg4WwbN7_camp",
          "templateId": "e3nzsdjhIsWraRK9_wt",
          "campaignName": "Test Campaign",
          "convUrl": "https://app.quickreply.ai/conversations/all/RFf5HkjghJkgct7b_conv?filter=all",
          "messageState": "DELIVERED",
          "messageSentTime": "2023-09-09T18:31:00.906Z",
          "price": {
            "utility": 0.34,
            "total": 0.34,
            "type": "UTILITY"
          },
          "customerName": "Utkarsh Kala",
          "customerPhone": "+919634687270",
          "text": "This is a test message [Complete Purchase,https://quickrepl.ai/]"
        }
      ]
    }
  ],
  "nextOffset": 50
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Fields marked with [\*️](https://emojipedia.org/asterisk/) are Required.
{% endhint %}

#### Sample cURL Request

{% code overflow="wrap" fullWidth="false" %}

```
curl --location 'https://cloudfunc.intelliticks.com/api/companyStats/fetchCampaignsData?startTime=1702146600000&endTime=1702233000000&offset=0' \
--header 'client-id: pKQYqdsAfd3DKofXo_c' \
--header 'secret-key: bEyckjhR33CHXKLm'
```

{% endcode %}

#### Sample Response Body

{% code overflow="wrap" fullWidth="false" %}

```json
{
  "success": true,
  "message": "success",
  "data": [
    {
      "event_id": "25558457545622",
      "type": "Checkout",
      "data": [
        {
          "campaignId": "pouqDjkhjkg4WwbN7_camp",
          "templateId": "e3nzsdjhIsWraRK9_wt",
          "campaignName": "Test Campaign",
          "convUrl": "https://app.quickreply.ai/conversations/all/RFf5HkjghJkgct7b_conv?filter=all",
          "messageState": "DELIVERED",
          "messageSentTime": "2023-09-09T18:31:00.906Z",
          "price": {
            "utility": 0.34,
            "total": 0.34,
            "type": "UTILITY"
          },
          "customerName": "Utkarsh Kala",
          "customerPhone": "+919634687270",
          "text": "This is a test message [Complete Purchase,https://quickrepl.ai/]"
        }
      ]
    }
  ],
  "nextOffset": 50
}
```

{% endcode %}
