Skip to content

Commit 44c6cb3

Browse files
fix: update examples in the analytics doc (#1377)
* fix examples in the doc * fix typo
1 parent 4b3b685 commit 44c6cb3

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

_docs/kb/articles/retrieve-usage-data-api.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Replace `{reportName}` with the specific report you want to query. Examples:
3838
```
3939
GET https://g.codefresh.io/api/analytics/reports/creditConsumption
4040
GET https://g.codefresh.io/api/analytics/reports/pipelineCreditConsumption
41-
GET https://g.codefresh.io/api/analytics/reports/activeCommiters
41+
GET https://g.codefresh.io/api/analytics/reports/activeCommitters
4242
```
4343

4444
**Discover reports and parameters**
@@ -61,43 +61,54 @@ GET https://g.codefresh.io/api/analytics/metadata
6161
- **Daily granularity:** 2 days – 45 days
6262
`?granularity=day&dateRange=YYYY-MM-DD&dateRange=YYYY-MM-DD`
6363

64-
**activeCommiters** supports:
64+
**activeCommitters** supports:
6565
- **Monthly granularity:** 3 months – 1 year
6666
`?granularity=month&dateRange=YYYY-MM-DD&dateRange=YYYY-MM-DD`
6767

6868
### Examples
6969

70-
**Credit consumption (monthly)**
70+
**Credit consumption for the last 3 months with monthly granularity**
7171
```
72-
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/creditConsumption?granularity=month&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq .
72+
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/creditConsumption?granularity=month&dateRange=$(date -v-3m +'%Y-%m-%d')&dateRange=$(date +'%Y-%m-%d')" | jq .
7373
```
7474

75-
**Pipeline credit consumption (daily)**
75+
**Credit consumption for the last 11 months without granularity**
7676
```
77-
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/pipelineCreditConsumption?granularity=day&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq .
77+
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/creditConsumption?dateRange=$(date -v-11m +'%Y-%m-%d')&dateRange=$(date +'%Y-%m-%d')" | jq .
7878
```
7979

80-
**Active committers (monthly)**
80+
**Pipeline credit consumption for the last 14 days with daily granularity**
8181
```
82-
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/activeCommiters?granularity=month&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq .
82+
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/pipelineCreditConsumption?granularity=day&dateRange=$(date -v-14d +'%Y-%m-%d')&dateRange=$(date +'%Y-%m-%d')" | jq .
83+
```
84+
85+
**Active committers for the last 6 months with monthly granularity**
86+
```
87+
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/activeCommitters?granularity=month&dateRange=$(date -v-6m +'%Y-%m-%d')&dateRange=$(date +'%Y-%m-%d')" | jq .
8388
```
8489

8590
## Suggested script
8691

8792
```
8893
#!/bin/bash
89-
# Expects these env vars:
90-
# API_KEY -> Codefresh API key
91-
# START_DATE -> "YYYY-MM-DD"
92-
# END_DATE -> "YYYY-MM-DD"
93-
94+
# Expects these variables will be passed as parameters:
95+
# API_KEY -> pass Codefresh API key
96+
API_KEY=$1
97+
# START_DATE -> pass start date formatted like "YYYY-MM-DD"
98+
START_DATE=$2
99+
# END_DATE -> pass end date formatted like "YYYY-MM-DD"
100+
END_DATE=$3
101+
# REPORT_NAME -> pass report name: creditConsumption | pipelineCreditConsumption | activeCommitters
102+
REPORT_NAME=$4
103+
104+
# Validate passed variables are not empty:
94105
: "${API_KEY:?Set API_KEY}"
95106
: "${START_DATE:?Set START_DATE}"
96107
: "${END_DATE:?Set END_DATE}"
108+
: "${REPORT_NAME:?Set REPORT_NAME}"
97109
98-
# Example: fetch credit consumption (monthly)
99-
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/creditConsumption?granularity=month&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq .
100-
# Adapt the endpoint for pipelineCreditConsumption or activeCommiters as needed.
110+
# Fetch report with monthly granularity
111+
curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/${REPORT_NAME}?granularity=month&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq .
101112
```
102113

103114
## Error handling

0 commit comments

Comments
 (0)