# Get Transaction Statistics

- Sandbox: `POST https://sandbox.payme.io/api/get-transaction-statistics`
- Production: `POST https://live.payme.io/api/get-transaction-statistics`

## Credentials

No credentials are documented for this endpoint.

This endpoint enable to get transaction average, based on the chosen period (`time_resolution`), transaction's status (pending/validated) and currency.

## Parameters

This endpoint takes no path, query or header parameters.

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `payme_client_key` | string | no | PayMe Partner Key. |
| `time_resolution` | string | no | The selected period. |
| `start_date` | string | no | The start date of the selected period. |
| `end_date` | string | no | The start date of the selected period. |
| `transaction_status` | array | no | Filter the status of the transactions that will take into account in the calculation. For all the transaction statuses see [Transaction Statuses](/guides-and-use-cases-migrated/lists-statuses/transaction-statuses). Example: pending |
| `sale_currency` | array | no | Sale currency. [3-letter ISO 4217 name](https://en.wikipedia.org/wiki/ISO_4217). Example: ILS |

### Request example

```json
{
  "payme_client_key": "XXXXXXXX",
  "time_resolution": "day",
  "start_date": "YYYY-MM-DD HH:MM:SS",
  "end_date": "YYYY-MM-DD HH:MM:SS",
  "transaction_status": [
    "pending",
    "validated"
  ],
  "sale_currency": [
    "ILS",
    "USD"
  ]
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/get-transaction-statistics' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "payme_client_key": "XXXXXXXX",
  "time_resolution": "day",
  "start_date": "YYYY-MM-DD HH:MM:SS",
  "end_date": "YYYY-MM-DD HH:MM:SS",
  "transaction_status": [
    "pending",
    "validated"
  ],
  "sale_currency": [
    "ILS",
    "USD"
  ]
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/get-transaction-statistics", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "payme_client_key": "XXXXXXXX",
    "time_resolution": "day",
    "start_date": "YYYY-MM-DD HH:MM:SS",
    "end_date": "YYYY-MM-DD HH:MM:SS",
    "transaction_status": [
      "pending",
      "validated"
    ],
    "sale_currency": [
      "ILS",
      "USD"
    ]
  }),
});

console.log(await response.text());
```

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/get-transaction-statistics",
    json={
        "payme_client_key": "XXXXXXXX",
        "time_resolution": "day",
        "start_date": "YYYY-MM-DD HH:MM:SS",
        "end_date": "YYYY-MM-DD HH:MM:SS",
        "transaction_status": [
            "pending",
            "validated",
        ],
        "sale_currency": [
            "ILS",
            "USD",
        ],
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "payme_client_key": "XXXXXXXX",
  "time_resolution": "day",
  "start_date": "YYYY-MM-DD HH:MM:SS",
  "end_date": "YYYY-MM-DD HH:MM:SS",
  "transaction_status": [
    "pending",
    "validated"
  ],
  "sale_currency": [
    "ILS",
    "USD"
  ]
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/get-transaction-statistics');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
```

## Responses

### 200 — OK (success)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | integer | Status of the request (0 - success, 1 - error) |
| `start_date` | string | The start date of the selected period. |
| `end_date` | string | The end date of the selected period. |
| `time_resolution` | string | The selected period. |
| `statistics` | object |  |
| `statistics.pending` | object | Transaction statistics in the chosen status |
| `statistics.pending.ILS` | array | Transaction statistics in the chosen currency |
| `statistics.pending.ILS[].sum` | integer |  |
| `statistics.pending.ILS[].count` | integer |  |
| `statistics.pending.ILS[].average` | integer |  |

```json
{
  "status_code": 0,
  "start_date": "YYYY-MM-DD HH:MM:SS",
  "end_date": "YYYY-MM-DD HH:MM:SS",
  "time_resolution": "day",
  "statistics": {
    "pending": {
      "ILS": [
        {
          "sum": 0,
          "count": 0,
          "average": 0
        },
        {
          "sum": 0,
          "count": 0,
          "average": 0
        }
      ]
    }
  }
}
```
