Authentication
The Streaks API uses API Keys for authentication. You can generate an API key for your project on the project's settings page.
Your API Key should be passed in the x-api-key
header with every request.
Here's an example using NodeJS with Axios:
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);
}
};
// Example usage
getCurrentStreak('123', '456', {
frequencyType: 'daily',
customFrequencyMS: 0,
weekStartDay: 'Monday',
countSamePeriod: false
});
Remember, this is a secret key - essentially a password to access and add to the events of your project. Do not share it with anyone outside your project or commit it to your repository. It should only be used on the server side of your application. In case you accidentally make an API key public, you can always delete it and regenerate a new one on the project's page.