Stat API: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
'''[https://kaminari.click/api/doc Подробное описание request-response по каждому эндпойнту].''' | '''[https://kaminari.click/api/doc Подробное описание request-response по каждому эндпойнту].''' | ||
=== '''Список эндпойнтов:''' === | |||
{| class="wikitable" | {| class="wikitable" | ||
!Method | !Method | ||
!Path | !Path | ||
Line 21: | Line 21: | ||
|получение данных для таблицы | |получение данных для таблицы | ||
|} | |} | ||
=== '''OPTIONS /api/stat/get''' === | |||
{| class="wikitable mw-collapsible" | {| class="wikitable mw-collapsible" | ||
|+ | |+Response | ||
!Key | !Key | ||
!Type | !Type | ||
Line 87: | Line 89: | ||
|Boolean * | |Boolean * | ||
|<code>list</code> с поиском на сервере | |<code>list</code> с поиском на сервере | ||
|} | |||
=== '''POST /api/stat/filter''' === | |||
{| class="wikitable mw-collapsible" | |||
|+Request | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|id | |||
|String | |||
|Название фильтра | |||
|- | |||
|searchQuery | |||
|String | |||
|Поисковой запрос | |||
|} | |||
{| class="wikitable mw-collapsible" | |||
|+Response | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|success | |||
|Boolean | |||
| | |||
|- | |||
|code | |||
| | |||
| | |||
|- | |||
|msg | |||
| | |||
| | |||
|- | |||
| colspan="3" |data | |||
|- | |||
|data.items | |||
|[{ id: Number, label: String }] | |||
|{ id: 1, label: "Param A" } | |||
|} | |||
=== '''POST /api/stat/data''' === | |||
{| class="wikitable mw-collapsible" | |||
|+Request | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|id | |||
|String | |||
| | |||
|- | |||
|name | |||
|String | |||
| | |||
|- | |||
|perPage | |||
|Number | |||
|Значение по умолчанию 50 | |||
|- | |||
|page | |||
|Number | |||
|Значение по умолчанию 1 | |||
|- | |||
|metrics | |||
|[String] | |||
| | |||
|- | |||
| colspan="3" |filters | |||
|- | |||
|dateFrom | |||
|String | |||
|Дата в формате Y-m-d | |||
|- | |||
|dateTo | |||
|String | |||
|Дата в формате Y-m-d | |||
|- | |||
|filters.filters | |||
|'''<filters>''' | |||
| | |||
|- | |||
|period | |||
|<nowiki>today | yesterday | currentWeek | 7days| month | null</nowiki> | |||
| | |||
|- | |||
|timezone | |||
|Number | |||
|От -12 до +12 | |||
|- | |||
|groups | |||
|[String] | |||
|'''Допустимые значения:''' | |||
time_hour, time_day, time_week. time_month, time_dateTime, sub_integration, sub_botType, sub_tbReason, sub_pid, sub_clickId, sub_placementId, sub_sspName, sub_domainName, sub_referer, sub_clickLink, sub_1...10, geo_language, geo_timezone, geo_country, geo_city, geo_provider, geo_ip, device_browser, device_browserEngine, device_os, device_realOs, device_device, device_type, device_connectionType, device_useragent, screen_width, screen_height, screen_orientation, screen_pixelDensity | |||
|- | |||
|compare | |||
|'''<compare>''' | |||
| | |||
|} | |||
{| class="wikitable mw-collapsible" | |||
|+Описание <filters> | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|id | |||
|String | |||
|'''Допустимые значения:'''time_hour, sub_integration, sub_botType, sub_pid, sub_clickId, sub_placementId, sub_tbReason, sub_sspName, sub_domainName, sub_referer, sub_clickLink, sub_1...10, bots_total, bots_crawler, bots_spoofing, bots_automated, bots_iFrame, lowQuality_proxy, lowQuality_automated, lowQuality_trafficCheats, geo_language, geo_timezone, geo_country, geo_city, geo_provider, geo_ip, lowQuality_total, lowQuality_spoofing, summary_validVisits, summary_validVisitsPc, lowQuality_totalPc, lowQuality_spoofingPc, bots_totalPc, bots_crawlerPc, bots_spoofingPc, bots_automatedPc, bots_iFramePc, lowQuality_proxyPc, lowQuality_automatedPc, lowQuality_trafficCheatsPc, device_browser, device_browserEngine, device_os, device_realOs, device_device, device_type, device_connectionType, device_useragent, screen_width, screen_height, screen_orientation, screen_pixelDensity, time_dateTime, summary_totalVisits, summary_uniqVisits, summary_uniqVisitsPc, summary_uniqUsers, summary_uniqUsersPc, summary_advDiscrep, summary_advDiscrepPc, summary_techLosses, summary_techLossesPc, summary_paidClicks, summary_paidClicksPc, feature_adBlock, feature_adBlockPc, feature_isMobile, feature_isMobilePc, feature_webView, feature_webViewPc | |||
|- | |||
|type | |||
|String | |||
| | |||
|- | |||
|range | |||
|{from: Number, to: Number} | |||
| | |||
|} | |||
{| class="wikitable mw-collapsible" | |||
|+Описание <compare> | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|dateFrom | |||
|String | |||
|Дата в формате Y-m-d | |||
|- | |||
|dateTo | |||
|String | |||
|Дата в формате Y-m-d | |||
|- | |||
|mode | |||
|<nowiki>compare_value | diff | percent</nowiki> | |||
| | |||
|- | |||
|sort | |||
|Boolean | |||
| | |||
|} | |||
{| class="wikitable mw-collapsible" | |||
|+Response | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|success | |||
|Boolean | |||
| | |||
|- | |||
|code | |||
| | |||
| | |||
|- | |||
|msg | |||
| | |||
| | |||
|- | |||
| colspan="3" |data | |||
|- | |||
|data.rows | |||
|['''<row>'''] | |||
|Описание строк таблицы | |||
|- | |||
|data.totalRows | |||
|Number | |||
|Общее количество элементов в таблице | |||
|- | |||
|data.total | |||
|'''<row>''' | |||
|Сумма по каждой колонке с учётом невидимых строк | |||
|- | |||
|data.page | |||
|Number | |||
|Текущая страница | |||
|- | |||
|data.perPage | |||
|Number | |||
|Количество элементов на странице | |||
|- | |||
|data.columns | |||
|['''<column>'''] | |||
|Описание столбцов | |||
|} | |||
{| class="wikitable mw-collapsible" | |||
|+ | |||
Описание <row> | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|value | |||
|String | |||
| | |||
|- | |||
|diff | |||
|<nowiki>String | null</nowiki> | |||
| | |||
|- | |||
|percent | |||
|<nowiki>Number | null</nowiki> | |||
| | |||
|- | |||
|compare_value | |||
|<nowiki>String | null</nowiki> | |||
| | |||
|} | |||
{| class="wikitable mw-collapsible" | |||
|+ | |||
Описание <column> | |||
!Key | |||
!Type | |||
!Description | |||
|- | |||
|field | |||
|String | |||
|ID метрики или группировки | |||
|- | |||
|type | |||
|<nowiki>string | number | float</nowiki> | |||
| | |||
|- | |||
|sortable | |||
|Boolean | |||
|Можно сортировать или нет | |||
|- | |||
|unit | |||
|<nowiki>String | null</nowiki> | |||
|Единица измерения. | |||
Например, % у процентных столбцов. | |||
|} | |} | ||
=== '''Примеры запросов.''' === | === '''Примеры запросов.''' === | ||
==== CURL ==== | |||
<code>curl -X 'OPTIONS' \ '<nowiki>https://kaminari.click/api/stat/get'</nowiki> \ -H 'accept: */*' 'Authorization: Bearer API_TOKEN'</code> | <code>curl -X 'OPTIONS' \ '<nowiki>https://kaminari.click/api/stat/get'</nowiki> \ -H 'accept: */*' 'Authorization: Bearer API_TOKEN'</code> | ||
Line 98: | Line 332: | ||
<code>curl -X POST '<nowiki>https://kaminari.click/api/stat/data'</nowiki> -d '{"id":null,"name":null,"groups":["time_day"],"metrics":["summary_totalVisits"],"filters":{"filters":[],"period":null,"timezone":0,"dateTo":"2022-08-15","dateFrom":"2022-08-15"},"compare":null}' -H 'content-type: application/json' -H 'Authorization: Bearer API_TOKEN'</code> | <code>curl -X POST '<nowiki>https://kaminari.click/api/stat/data'</nowiki> -d '{"id":null,"name":null,"groups":["time_day"],"metrics":["summary_totalVisits"],"filters":{"filters":[],"period":null,"timezone":0,"dateTo":"2022-08-15","dateFrom":"2022-08-15"},"compare":null}' -H 'content-type: application/json' -H 'Authorization: Bearer API_TOKEN'</code> | ||
==== NodeJS ==== | |||
const https = require('https'); | const https = require('https'); | ||
Revision as of 18:55, 12 April 2023
Подробное описание request-response по каждому эндпойнту.
Список эндпойнтов:
Method | Path | Description |
---|---|---|
OPTIONS | /api/stat/get | Возвращает все возможные группировки и метрики, сгруппированные по категориям. |
POST | /api/stat/filter | получение данных для фильтра |
POST | /api/stat/data | получение данных для таблицы |
OPTIONS /api/stat/get
Key | Type | Description |
---|---|---|
success | Boolean | |
code | ||
msg | ||
data | ||
data.groups | { groupTitle: [<item>, …] } | Каждый groupTitle должен быть ключом в словаре reportConstructor
|
data.metrics | { metricTitle: [<item>, …] } | Каждый metricTitle должен быть ключом в словаре reportConstructor
|
data.periods | [ 'today', 'yesterday', '7days', '14days', 'month', 'prevMonth' ] | У каждого параметра должен быть ключ в словаре datePicker
|
data.ttl | { 1: null | number , ... }
|
Key | Type | Description |
---|---|---|
id | String | <groupTitle или metricTitle>
+ подчёркивание + <название метрики или группировки> (groupTitle_id) Должен иметь ключ в словаре |
icon | date | text | number
|
Иконка типа |
sources | [Number] | |
filterType | range | list | value | value_like | value_combined
|
см. Описание filterType |
filterSync | Boolean * | list с поиском на сервере
|
POST /api/stat/filter
Key | Type | Description |
---|---|---|
id | String | Название фильтра |
searchQuery | String | Поисковой запрос |
Key | Type | Description |
---|---|---|
success | Boolean | |
code | ||
msg | ||
data | ||
data.items | [{ id: Number, label: String }] | { id: 1, label: "Param A" } |
POST /api/stat/data
Key | Type | Description |
---|---|---|
id | String | |
name | String | |
perPage | Number | Значение по умолчанию 50 |
page | Number | Значение по умолчанию 1 |
metrics | [String] | |
filters | ||
dateFrom | String | Дата в формате Y-m-d |
dateTo | String | Дата в формате Y-m-d |
filters.filters | <filters> | |
period | today | yesterday | currentWeek | 7days| month | null | |
timezone | Number | От -12 до +12 |
groups | [String] | Допустимые значения:
time_hour, time_day, time_week. time_month, time_dateTime, sub_integration, sub_botType, sub_tbReason, sub_pid, sub_clickId, sub_placementId, sub_sspName, sub_domainName, sub_referer, sub_clickLink, sub_1...10, geo_language, geo_timezone, geo_country, geo_city, geo_provider, geo_ip, device_browser, device_browserEngine, device_os, device_realOs, device_device, device_type, device_connectionType, device_useragent, screen_width, screen_height, screen_orientation, screen_pixelDensity |
compare | <compare> |
Key | Type | Description |
---|---|---|
id | String | Допустимые значения:time_hour, sub_integration, sub_botType, sub_pid, sub_clickId, sub_placementId, sub_tbReason, sub_sspName, sub_domainName, sub_referer, sub_clickLink, sub_1...10, bots_total, bots_crawler, bots_spoofing, bots_automated, bots_iFrame, lowQuality_proxy, lowQuality_automated, lowQuality_trafficCheats, geo_language, geo_timezone, geo_country, geo_city, geo_provider, geo_ip, lowQuality_total, lowQuality_spoofing, summary_validVisits, summary_validVisitsPc, lowQuality_totalPc, lowQuality_spoofingPc, bots_totalPc, bots_crawlerPc, bots_spoofingPc, bots_automatedPc, bots_iFramePc, lowQuality_proxyPc, lowQuality_automatedPc, lowQuality_trafficCheatsPc, device_browser, device_browserEngine, device_os, device_realOs, device_device, device_type, device_connectionType, device_useragent, screen_width, screen_height, screen_orientation, screen_pixelDensity, time_dateTime, summary_totalVisits, summary_uniqVisits, summary_uniqVisitsPc, summary_uniqUsers, summary_uniqUsersPc, summary_advDiscrep, summary_advDiscrepPc, summary_techLosses, summary_techLossesPc, summary_paidClicks, summary_paidClicksPc, feature_adBlock, feature_adBlockPc, feature_isMobile, feature_isMobilePc, feature_webView, feature_webViewPc |
type | String | |
range | {from: Number, to: Number} |
Key | Type | Description |
---|---|---|
dateFrom | String | Дата в формате Y-m-d |
dateTo | String | Дата в формате Y-m-d |
mode | compare_value | diff | percent | |
sort | Boolean |
Key | Type | Description |
---|---|---|
success | Boolean | |
code | ||
msg | ||
data | ||
data.rows | [<row>] | Описание строк таблицы |
data.totalRows | Number | Общее количество элементов в таблице |
data.total | <row> | Сумма по каждой колонке с учётом невидимых строк |
data.page | Number | Текущая страница |
data.perPage | Number | Количество элементов на странице |
data.columns | [<column>] | Описание столбцов |
Key | Type | Description |
---|---|---|
value | String | |
diff | String | null | |
percent | Number | null | |
compare_value | String | null |
Key | Type | Description |
---|---|---|
field | String | ID метрики или группировки |
type | string | number | float | |
sortable | Boolean | Можно сортировать или нет |
unit | String | null | Единица измерения.
Например, % у процентных столбцов. |
Примеры запросов.
CURL
curl -X 'OPTIONS' \ 'https://kaminari.click/api/stat/get' \ -H 'accept: */*' 'Authorization: Bearer API_TOKEN'
curl -X POST 'https://kaminari.click/api/stat/filter' -d '{"id":"device_type","searchQuery":"","dateFrom":"2023-01-05","dateTo":"2023-01-05"}' -H 'content-type: application/json' -H 'Authorization: Bearer API_TOKEN'
curl -X POST 'https://kaminari.click/api/stat/data' -d '{"id":null,"name":null,"groups":["time_day"],"metrics":["summary_totalVisits"],"filters":{"filters":[],"period":null,"timezone":0,"dateTo":"2022-08-15","dateFrom":"2022-08-15"},"compare":null}' -H 'content-type: application/json' -H 'Authorization: Bearer API_TOKEN'
NodeJS
const https = require('https'); const options = { host: 'kaminari.click', port: 443, path: '/api/stat/get', method: 'POST', headers: { 'Authorization': 'Bearer API_TOKEN' } }; https .get(options, (resp) => { let data = ''; resp.on('data', (chunk) => { data += chunk; }); resp.on('end', () => { try { data = JSON.parse(data); } catch { console.log(data); } }); }) .on("error", (err) => { console.log("Error: " + err.message); });
PHP
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://kaminari.click/api/stat/get'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'OPTIONS'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'accept: */*', ]); $response = curl_exec($ch); curl_close($ch);
Python
import requests headers = { 'accept': '*/*', } response = requests.options('https://kaminari.click/api/stat/get', headers=headers) response = requests.options('http://Authorization: Bearer API_TOKEN', headers=headers)