-
-
Notifications
You must be signed in to change notification settings - Fork 30
Beaver Habit Tracker API How‐to Guide
Henry Zhu edited this page Dec 15, 2024
·
2 revisions
The Beaver Habit Tracker API gives you the ability to create, update, list and complete habits with ease.
Please check out this Swagger UI documentation for all the APIs.
Postman Collection containing the HTTP requests used in this walkthrough is provided in this gist.
This task produces an access token with your username and password:
# request
curl --request POST \
--url {{endpoint}}/auth/login \
--header 'accept: application/json' \
--header 'content-type: application/x-www-form-urlencoded' \
--data grant_type=password \
--data 'username={{username}}' \
--data 'password={{password}}'
# response
{
"access_token": "<token>",
"token_type": "bearer"
}
# request
curl --request GET \
--url {{endpoint}}/api/v1/habits \
--header 'accept: application/json' \
--header 'authorization: Bearer {{accessToken}}'
# response
[
{
"id": "f41e44",
"name": "Order pizz"
},
{
"id": "87e537",
"name": "Running"
},
...
]
# request
curl --request POST \
--url {{endpoint}}/api/v1/habits/f41e44/completions \
--header 'authorization: Bearer {{accessToken}}' \
--header 'content-type: application/json' \
--data '{
"date_fmt": "%d-%m-%Y",
"date": "16-12-2024",
"done": true
}'
# response
{
"day": "16-12-2024",
"done": true
}
# request
curl --location '{{endpoint}}/api/v1/habits/f41e44/completions?date_fmt=%d-%m-%Y&date_start=01-12-2024&date_end=30-12-2024&sort=asc' \
--header 'accept: application/json' \
--header 'Authorization: Bearer {{accessToken}}'
# response
[
"10-12-2024",
"12-12-2024",
"16-12-2024"
]