# 기간 집계

원문: https://commerce.bootpay.ai/api/alimtalk-ops/history/stats

> 알림톡 발송량과 성공률, 예상 과금액을 기간별로 집계하는 API

알림톡 발송량과 성공률, 예상 과금액을 기간별로 집계합니다. 일자별로 쌓아 둔 집계에서 읽습니다.

::: endpoint
method: GET
url: https://message.bootapi.com/alimtalk/messages/stats
auth: [Basic Auth](https://commerce.bootpay.ai/api/server/authentication)
:::

## 요청 파라미터

::: parameters

| 파라미터 | 타입 | 필수 | 설명 |
|---------|------|------|------|
| s_at | String | N | 조회 시작 시각 (ISO8601) |
| e_at | String | N | 조회 종료 시각 (ISO8601) |

:::

기간 규칙은 [발송내역 목록](https://commerce.bootpay.ai/api/alimtalk-ops/history/list)과 같습니다. 기본 30일, 최대 92일입니다. 응답 `period` 의 시각 형식은 [응답의 시각 형식](https://commerce.bootpay.ai/api/alimtalk/common#응답의-시각-형식)을 참고합니다.

## 코드 예제

::: code-group

```bash [cURL]
curl -X GET "https://message.bootapi.com/alimtalk/messages/stats?s_at=2026-08-01T00:00:00%2B09:00" \
  -H "Authorization: Basic {base64(client_key:secret_key)}"
```

```javascript [Node.js]
import { BootpayCommerce } from '@bootpay/backend-js'

const commerce = new BootpayCommerce({
    client_key: 'your-commerce-client-key',
    secret_key: 'your-commerce-secret-key',
    mode: 'production'
})

const response = await commerce.alimtalkMessage.stats({ s_at: '2026-08-01T00:00:00+09:00' })
console.log(response.totals)
```

```python [Python]
from bootpay_backend import BootpayCommerce

commerce = BootpayCommerce(
    client_key='your-commerce-client-key',
    secret_key='your-commerce-secret-key',
    mode='production'
)

response = commerce.alimtalk_message.stats({
    's_at': '2026-08-01T00:00:00+09:00'
})
print(response['totals'])
```

```php [PHP]
use Bootpay\ServerPhp\BootpayCommerceApi;

$commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
$response = $commerce->alimtalkMessage->stats(['s_at' => '2026-08-01T00:00:00+09:00']);
print_r($response->totals);
```

```java [Java]
import kr.co.bootpay.store.BootpayStore;
import kr.co.bootpay.store.model.request.TokenPayload;
import kr.co.bootpay.store.model.response.BootpayStoreResponse;

TokenPayload tp = new TokenPayload("your-commerce-client-key", "your-commerce-secret-key");
BootpayStore commerce = new BootpayStore(tp).withToken();

// 시작일만 넘기고 종료일은 서버 기본값을 씁니다.
BootpayStoreResponse response = commerce.alimtalkMessage.stats("2026-08-01T00:00:00+09:00", null);
System.out.println(response.getData().get("totals"));
```

```ruby [Ruby]
require 'bootpay'

commerce = BootpayStore::RestClient.new(client_key: 'your-commerce-client-key', secret_key: 'your-commerce-secret-key')
response = commerce.alimtalk_message_stats(s_at: '2026-08-01T00:00:00+09:00')
puts response.data[:totals]
```

```go [Go]
import "github.com/bootpay/backend-go/v2"

commerce := bootpay.NewCommerceAPI("your-commerce-client-key", "your-commerce-secret-key", nil, "production")
response, err := commerce.AlimtalkMessage.Stats("2026-08-01T00:00:00+09:00", "") // 두 번째 인자 e_at(종료 시각)은 비우면 보내지 않습니다
fmt.Println(response, err)
```

```csharp [.NET]
using Bootpay.Commerce;
using Bootpay.Commerce.Models;
using Newtonsoft.Json.Linq;

var commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
var response = await commerce.AlimtalkMessageStats(new AlimtalkMessageStatsParams {
    SAt = "2026-08-01T00:00:00+09:00"
});
var body = JObject.Parse(await response.Content.ReadAsStringAsync());
Console.WriteLine(body["totals"]);
```

:::

## 응답

```json
{
  "period": {
    "from": "2026-08-01 00:00:00 +0900",
    "to": "2026-08-27 10:00:00 +0900"
  },
  "totals": {
    "sent": 1240,
    "success": 1198,
    "failed": 30,
    "opted_out_hit": 8,
    "rejected": 4,
    "canceled": 2,
    "success_rate": 0.9756
  },
  "daily": [
    { "date": "20260801", "sent": 40, "success": 39, "failed": 1, "opted_out_hit": 0, "rejected": 0, "canceled": 0 }
  ],
  "billing": {
    "billable_count": 1198,
    "unit_price": 8.5,
    "unit_price_source": "cache",
    "amount": 10183.0
  }
}
```

### totals

| 필드 | 설명 |
|------|------|
| sent | 접수된 전체 건수 |
| success | 전달 성공 |
| failed | 전달 실패 |
| opted_out_hit | [발송 제외 목록](https://commerce.bootpay.ai/api/alimtalk-ops/optout)에 걸려 걸러진 건수 |
| rejected | 벌크 발송에서 변수 누락·규격 위반으로 건별 거부된 건수. 벌크의 번호 오류와 단건 발송의 거부는 세지 않아서 벌크 응답의 `rejected` 합과 다를 수 있습니다 |
| canceled | 예약 취소된 건수 |
| success_rate | `success ÷ (success + failed)`. 확정된 건이 없으면 `null` |

성공률의 분모는 **결과가 확정된 건**입니다. 아직 전송 중인 건은 분모에 넣지 않습니다.

### daily

날짜별 같은 지표입니다. `date` 는 `YYYYMMDD` 형식이고, **발송이 없는 날도 0 으로 채워** 돌려줍니다.

날짜는 **그 사건이 일어난 날**(Asia/Seoul) 기준입니다. `sent` 는 접수일, `success`·`failed` 는 결과가 확정된 날, `canceled` 는 취소한 날에 쌓입니다. 따라서 같은 기간이라도 접수 시각으로 거르는 [발송내역 목록](https://commerce.bootpay.ai/api/alimtalk-ops/history/list)과 건수가 다를 수 있습니다.

### billing

| 필드 | 설명 |
|------|------|
| billable_count | 알림톡으로 과금되는 건수(전달 성공 건) |
| unit_price | 알림톡 단가 |
| unit_price_source | `cache`(확정 요율) 또는 `default`(잠정 단가) |
| amount | `billable_count × unit_price` |

::: warning 확정 청구액이 아닙니다
`unit_price_source` 가 `default` 면 요율표에 등록된 값이 아니라 잠정 단가로 계산한 값입니다. 이때 `amount` 는 참고용으로만 봅니다.
:::
