Prerequisites
Make sure to follow the instructions in our api key generation section to get a short lived token beforehand and use kapptivate's monitoring APIs.
Step 1 : Generate your JWT Token
In order to use kapptivate API you will need to use a JWT Token in the header of your request.To generate that token, you need to call the refresh_token endpoint using your API key.
The Content-Type : Application/JSON should be present in your Header. Here is a sample of the request you need to POST.
POST https://your_domain_name.kapptivate.com/api/auth/refresh-token/
{
"refresh_token": "YOUR_API_KEY"
}
The result of that request will be your JWT Token. Per default, this token is only valid for 2 mins.
Step 2 : Make a query to retrieve values
kapptivate's measurements are stored into a database called influxDB. The metrics API lets you query your datas using the influx Query language for which you can find the full documentation here.
You need then to call the metrics_proxy endpoint using the previously acquired JWT Token. You also need to provide a query which will specify which are the values you need to retrieve.
GET -H "Authorization: JWT " /api/metrics/query/
Each request will require a query and an operator. Query parameters:
-
q: The influx query
-
db: The operator for which the query will be applied
Example:
GET -H "Authorization: JWT " /api/metrics/query/q=SHOW+MEASUREMENTS&db=kapptivate
The db parameter can be requested by sending an email to support@kapptivate.com
Here is a sample of a request to get the Success Rate for all tests in kapptivate with results grouped by 5 minutes over the last 2 hours.
GET https://your_domain_name.kapptivate.com/metrics_proxy/api/query/custom/?q=
SELECT sum("number_success")/(sum("number_success")+sum("number_failed"))*100
AS "Success Rate (%)"
FROM "test"
WHERE time=now() - 2h
GROUP BY time(5m)&db=kapptivate
HEADER: Content-Type : Application/JSON
HEADER: Authorization: JWT YOUR_REFRESH_TOKEN
Response:
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "test",
"columns": [
"time",
"Success Rate (%)"
],
"values": [
[
"2021-05-03T08:10:00Z",
100
],
[
"2021-05-03T08:15:00Z",
100
],
[
"2021-05-03T08:20:00Z",
100
],
[
"2021-05-03T08:25:00Z",
100
],
[
"2021-05-03T08:30:00Z",
100
],
[
"2021-05-03T08:35:00Z",
100
],
[
"2021-05-03T08:40:00Z",
100
],
[
"2021-05-03T08:45:00Z",
100
],
[
"2021-05-03T08:50:00Z",
100
],
[
"2021-05-03T08:55:00Z",
100
],
[
"2021-05-03T09:00:00Z",
100
],
[
"2021-05-03T09:05:00Z",
100
],
[
"2021-05-03T09:10:00Z",
100
],
[
"2021-05-03T09:15:00Z",
100
],
[
"2021-05-03T09:20:00Z",
100
],
[
"2021-05-03T09:25:00Z",
100
],
[
"2021-05-03T09:30:00Z",
100
],
[
"2021-05-03T09:35:00Z",
100
],
[
"2021-05-03T09:40:00Z",
100
],
[
"2021-05-03T09:45:00Z",
100
],
[
"2021-05-03T09:50:00Z",
100
],
[
"2021-05-03T09:55:00Z",
100
],
[
"2021-05-03T10:00:00Z",
100
],
[
"2021-05-03T10:05:00Z",
100
],
[
"2021-05-03T10:10:00Z",
100
]
]
}
]
}
]
}