# GET - Get stats

The stats endpoint allows you to track the result transactional messages using its group id.

### Request structure

#### Route

The transactional API exposes a GET endpoint at: `https://api.batch.com/1.1/BATCH_API_KEY/transactional/stats/GROUP_ID`

Here are examples of valid cURL, PHP or Python requests syntax:

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET "https://api.batch.com/1.1/BATCH_API_KEY/transactional/stats/GROUP_ID?since=2018-03-01&until=2018-03-10" \
-H "Content-Type: application/json" \
-H "X-Authorization: BATCH_REST_API_KEY"
```

{% endtab %}

{% tab title="PHP" %}

```php
use GuzzleHttp\Client;
$client = new Client();
$response = $client->request("GET", "https://api.batch.com/1.1/BATCH_API_KEY/transactional/stats/GROUP_ID?since=2018-03-01&until=2018-03-10", [
	"headers" => [
		"Content-Type" => "application/json",
		"X-Authorization" => "BATCH_REST_API_KEY"
	]
]);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests, json
response = requests.request("GET", "https://api.batch.com/1.1/BATCH_API_KEY/transactional/stats/GROUP_ID?since=2018-03-01&until=2018-03-10",
	headers={
		'Content-Type': 'application/json'
		'X-Authorization': 'BATCH_REST_API_KEY'
	}
)
```

{% endtab %}
{% endtabs %}

The `GROUP_ID` value is the id you set when you [create](https://doc.batch.com/developer/api/mep/transactional/send) a transactional message.

> **Note**: Only LIVE API Keys are supported by this API

#### Get parameters

<table><thead><tr><th width="176">Id</th><th>Description</th></tr></thead><tbody><tr><td><code>since</code></td><td><strong>String</strong> - <em>Required. Must be lower than 'until' parameter.</em><br>Value that indicates the first date of the window over which stats are fetched. The maximum window size is 6 months.<br><em>E.g.</em><code>"/transactional/stats/GROUP_ID?since=2018-03-01"</code></td></tr><tr><td><code>until</code></td><td><strong>String</strong> - <em>Required, Default : today's date (GMT)</em><br>Value that indicates the last date of the window over which stats are fetched.<br><em>E.g.</em><code>"/transactional/stats/GROUP_ID?since=2018-03-01&#x26;until=2018-03-10"</code></td></tr></tbody></table>

Here is an example of a valid cURL CLI request, which would return daily stats about the group id **welcome** from 1 to 10 March 2018 :

```
curl -H "Content-Type: application/json" -H "X-Authorization: BATCH_REST_API_KEY" -X GET
"https://api.batch.com/1.1/BATCH_API_KEY/transactional/stats/welcome?since=2018-03-01&until=2018-03-10"
```

#### Headers

In order to authenticate with the API, you need to provide your **company REST API Key** as the value of the `X-Authorization` header.

### Responses

#### Success

If the GET to the API endpoint is successfull you will receive an HTTP 200 confirmation and information on your campaign.

```json
{
    "group_id": "welcome",
    "detail": [
        {
            "date": "2018-03-05",
            "sent": 754,
            "direct_open": 102,
            "influenced_open": 98,
            "reengaged": 12,
            "errors": 0
        },
        {
            "date": "2018-03-07",
            "sent": 582,
            "direct_open": 96,
            "influenced_open": 85,
            "reengaged": 12,
            "errors": 1
        }
    ]
}
```

You can use this information to show the results of your transactional messages in your business intelligence tools.

Also, you can easily calculate the **open-rate** by using the following formula:\
**open-rate** = (`direct_open` + `influenced_open`) / `sent`

#### Failure

If the GET data does not meet the API requirements you will receive an actionable error message. Contact us at <support@batch.com> if you need further support.

* `AUTHENTICATION_INVALID` (Http status code: 401, Error code: 10)
* `API_MISUSE` (Http status code: 403, Error code: 12)
* `ROUTE_NOT_FOUND` (Http status code: 404, Error code: 20)
* `SERVER_ERROR` (Http status code: 500, Error code: 0)
