Semestra

Habit streak plugin

GET
/habit/instances/{instance_id}/checkins

Use to see which days a habit was done. The range is at most 400 days and in the Program's time zone.

Authorization

cookiesemestra_session<token>

Set by the sign-in endpoints for the web app. Requests other than GET, HEAD and OPTIONS also need the X-Semestra-CSRF header set to the semestra_csrf cookie.

Path Parameters

instance_id*Instance Id

Habit card instance id

Query Parameters

from_date*From Date

First day to list (inclusive)

Formatdate
to_date*To Date

Last day to list (inclusive)

Formatdate

Response Body

Successful Response

application/json
  1. response
items*array<>

Checked days, ascending

Example Request
curl -X GET 'https://example.com/habit/instances/string/checkins?from_date=2019-08-24&to_date=2019-08-24'
Example Response
{  "items": [    "2019-08-24"  ]}
POST
/habit/instances/{instance_id}/checkins/toggle

The habit card's click: a checked day becomes unchecked and the other way round. Days older than 7 days or in the future are refused.

Authorization

cookiesemestra_session<token>

Set by the sign-in endpoints for the web app. Requests other than GET, HEAD and OPTIONS also need the X-Semestra-CSRF header set to the semestra_csrf cookie.

Path Parameters

instance_id*Instance Id

Habit card instance id

Request Body

application/json
  1. body
date*Date

Day to check or uncheck, in the Program's time zone: today or up to 7 days ago

Formatdate

Response Body

Successful Response

application/json
  1. response
date*Date
Formatdate
checked*Checked

Whether the day is checked after the call

stats*
Example Request
curl -X POST 'https://example.com/habit/instances/string/checkins/toggle' \  -H 'Content-Type: application/json' \  -d '{  "date": "2019-08-24"}'
Example Response
{  "date": "2019-08-24",  "checked": true,  "stats": {    "goal": "daily",    "weekly_target": 0,    "current_streak": 0,    "longest_streak": 0,    "total": 0,    "period_done": 0,    "period_target": 0,    "today": "2019-08-24",    "week_start": 1,    "checked_today": true  }}
GET
/habit/instances/{instance_id}/stats

Use to answer how long the user's streak is or how often they did a habit. For a weekly goal the streaks count weeks that reached the weekly target; a streak stays alive while the running day (or week) is still open. Also returns today's date in the Program's time zone.

Authorization

cookiesemestra_session<token>

Set by the sign-in endpoints for the web app. Requests other than GET, HEAD and OPTIONS also need the X-Semestra-CSRF header set to the semestra_csrf cookie.

Path Parameters

instance_id*Instance Id

Habit card instance id

Response Body

Successful Response

application/json
  1. response
goal*Goal
Value in"daily""weekly"
weekly_target*Weekly Target

Check-ins needed per week (weekly goal)

current_streak*Current Streak

Days (daily goal) or weeks (weekly goal) in a row

longest_streak*Longest Streak
total*Total

All checked days

period_done*Period Done

Check-ins in the current day (daily) or week (weekly)

period_target*Period Target

1 for a daily goal, the weekly target otherwise

today*Today

Today in the Program's time zone

Formatdate
week_start*Week Start

First day of the week: 1 Monday, 7 Sunday

Value in17
checked_today*Checked Today
Example Request
curl -X GET 'https://example.com/habit/instances/string/stats'
Example Response
{  "goal": "daily",  "weekly_target": 0,  "current_streak": 0,  "longest_streak": 0,  "total": 0,  "period_done": 0,  "period_target": 0,  "today": "2019-08-24",  "week_start": 1,  "checked_today": true}