# getSpendingStats

Returns your spending for one UTC day, hour by hour: number of tasks and money spent. Failed and refunded tasks are not counted.

`POST https://unlock-api.com/getSpendingStats`

> date is any Unix time inside the day you want. Without it, today (UTC) is used.

## Request parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `clientKey` | String | Yes | Your API key, 32 characters, from the account page. |
| `date` | Integer | No | Unix time inside the day to report. Default: today in UTC. |

## Request

```json
{
  "clientKey": "YOUR_API_KEY",
  "date": 1791590400
}
```

## Response

### Success

```json
{
  "errorId": 0,
  "data": [
    {
      "dateFrom": 1791590400,
      "dateTill": 1791593999,
      "volume": 120,
      "money": 0.066
    },
    {
      "dateFrom": 1791594000,
      "dateTill": 1791597599,
      "volume": 0,
      "money": 0
    }
  ]
}
```

## Response fields

| Name | Type | Description |
|---|---|---|
| `errorId` | Integer | 0 when the request worked, 1 when it did not. |
| `data` | Array | 24 rows, one per hour: dateFrom, dateTill, volume (tasks) and money (US dollars). |

## Code samples

### cURL

```bash
curl -s https://unlock-api.com/getSpendingStats \
  -H "Content-Type: application/json" \
  -d '{"clientKey":"YOUR_API_KEY","date":1791590400}'
```

### Python

```python
import requests

r = requests.post("https://unlock-api.com/getSpendingStats", json={
    "clientKey": "YOUR_API_KEY",
    "date": 1791590400
}).json()
print(r)
```

### Node.js

```javascript
const r = await fetch("https://unlock-api.com/getSpendingStats", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    "clientKey": "YOUR_API_KEY",
    "date": 1791590400
  }),
}).then((res) => res.json());
console.log(r);
```

## Errors this method can return

- `ERROR_KEY_DOES_NOT_EXIST`: The key is wrong. Copy it again from the account page. (in.php and res.php: ERROR_WRONG_USER_KEY)
