Get Current Streak
Retrieves the current streak information for a given project and streak ID.
There are several different ways to think about what counts as a 'streak', so this endpoint aims to provide options to allow for the different criteria. The different options are described in the Parameters section below.
In addition, there are some hardcoded assumptions about the streaks that are not currently configurable. These assumptions are:
- During streak calculation, each event’s source time zone is used. So, if there was an event at local time 11PM one day, and local time 1am the next day (even if the two events are in different time zones), that counts as a daily streak of 2, even if the two events would be within the same calendar day in UTC.
Endpoint
GET /events/:projectId/currentStreak/:streakId?<streakConfig>
Authentication
This endpoint requires API key authentication. See the Authentication for more information.
Parameters
Path Parameters
-
projectId
- (required)
- The ID of the project.
-
streakId
- (optional)
- The ID of the streak.
- Default is
default
.
Query Parameters
StreakConfig
(optional)
- The object used to customize the streak calculation options.
StreakConfig Fields:
frequencyType
:FrequencyType
- The frequency type of the streak (e.g., daily, weekly, monthly, custom). Events in two consecutive 'frequency periods' will continue a streak, and the amount of time between events is not considered (unless using 'custom' frequency). For example, an event at 1:00am on Monday followed by an event at 11:00pm on Tuesday will count towards a daily streak, even though the two events are more than 24 hours apart.
- Default is
Daily
.
customFrequencyMS
:number
- Custom frequency in milliseconds. Used only when
frequencyType
iscustom
. - Default is
0
.
- Custom frequency in milliseconds. Used only when
weekStartDay
:WeekStartDay
- The start day of the week. Only considered if
frequencyType
isweekly
. - Default is
Monday
.
- The start day of the week. Only considered if
countSamePeriod
:boolean
- Flag to indicate if multiple events within the same period (defined by the frequencyType option) should be counted towards the streak. For example, if 'false' and the frequency is 'weekly', and there are two events in the same week, only one of them will count towards the streak. If 'true', both events will count towards the streak.
- Default is
false
.
Response
Streak
: number
- The current number of events completed on time in a row for the provided project ID, streak ID, and configuration.
NodeJS Example
import axios from 'axios';
const getCurrentStreak = async (projectId, streakId, config) => {
try {
const response = await axios.get(`https://api.streaksapi.com/events/${projectId}/currentStreak/${streakId}`, {
params: config,
headers: {
'x-api-key': 'YOUR_API_KEY'
}
});
console.log('Current Streak:', response);
} catch (error) {
console.error('Error fetching current streak:', error);
}
};
getCurrentStreak('123', '456', {
frequencyType: 'daily',
customFrequencyMS: 0,
weekStartDay: 'Monday',
countSamePeriod: false
});