# S4 static CDN API

> An introduction to the Bitiful S4 static CDN API.

## Get a console API token

Get one from the console: <https://console.bitiful.com/apiToken>

## Data transfer

> **Tip**
>
> **Parameters**
>
> **start_time** - Start time, timestamp, in seconds
>
> **end_time**   - End time, timestamp, in seconds
>
> **period**     - Aggregation interval. One of hourly / daily / monthly.

### Edge traffic

```shell
curl --get -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cdn/data/{cdn-domain}/traffic?start_time={start_time}&end_time={end_time}&period={period}"
```

### Origin fetch traffic

```shell
curl --get -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cdn/data/{cdn-domain}/traffic_origin?start_time={start_time}&end_time={end_time}&period={period}"
```

## Requests

> **Tip**
>
> **Parameters**
>
> **start_time**   Start time, timestamp, in seconds
>
> **end_time**     End time, timestamp, in seconds
>
> **period**       Aggregation interval. One of hourly / daily / monthly.

### Edge requests

```shell
curl --get -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cdn/data/{cdn-domain}/request?start_time={start_time}&end_time={end_time}&period={period}"
```

### Origin fetch requests

```shell
curl --get -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cdn/data/{cdn-domain}/request_origin?start_time={start_time}&end_time={end_time}&period={period}"
```

## CDN real-time logs

Only logs from the last 3 days are available.

> **Tip**
>
> **Parameters**
>
> **start_time**   Start time as a timestamp in nanoseconds, used for pagination. Example: 1723046499000000000
>
> **codes**        Filter by HTTP status code. One of 2XX / 3XX / 4XX / 5XX / ALL. Defaults to ALL.
>
> **limit**        Number of entries to return per request. Maximum: 1000.

```shell
curl -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cdn/data/{cdn-domain}/logs?start_time={start_time}&codes={codes}&limit={limit}"
```

## Purge the CDN cache

> **Tip**
>
> **Request**
>
> Method: POST
>
> Content-Type: application/json
>
> **Parameters**
>
> **type**          Purge type: `url` or `directory`, which purge URLs or directories respectively.
>
> **url_list**     Array of strings listing the URLs/directories to purge. The array can contain at most 20 elements, and URLs can't contain the asterisk character `*`. If a directory or file name in a URL contains special characters such as `%`, URL-encode it first.

```shell
curl -X POST -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cdn/cache/refresh" -d '{"type": "url", "url_list": ["https://xxx.com/yyy/zzz.png", "https://aaa.com/bbb/ccc.png"]}'
```
