Create Event
Creates a new event within a project and streak.
Endpoint
POST /events/project/:projectId
Authentication
- Requires API key authentication. See the Authentication page for more information.
Path Parameters
-
projectId
- (required)
- The ID of the project for which to create the event. This is used in case you have multiple projects to track events for.
- You can retrieve the project ID from the project's page, which you can find by going to your dashboard and selecting the project.
Request Body
Event
- (required)
- The object containing the event details. Pass this in the request body as JSON.
Fields
projectId
:string
- (required)
- The ID of the project for which the event is being created.
userId
:string
- (required)
- The ID of the user associated with the event. This is the ID of the user within your app who triggered the event.
streakId
:string
- (optional)
- The ID of the streak associated with the event. This is used in case users in your app can have multiple streaks going, for example if they are tracking multiple habits or fitness goals.
- Default is
default
.
timestampISO
:string
- (required)
- The timestamp of the event in ISO format. Must be a valid ISO date string.
Response
Event
- The event object that was created.
Fields
id
:string
- The unique identifier of the event.projectId
:string
- The ID of the project associated with the event.userId
:string
- The ID of the user associated with the event.streakId
:string
- The ID of the streak associated with the event.timestampISO
:string
- The timestamp of the event in ISO format.
NodeJS Example
import axios from 'axios';
const createEvent = async (projectId, eventData) => {
try {
const response = await axios.post(`https://api.streaksapi.com/events/project/${projectId}`, eventData, {
headers: {
'x-api-key': 'YOUR_API_KEY'
}
});
console.log('Event Created:', response.data);
} catch (error) {
console.error('Error creating event:', error);
}
};
createEvent('123', {
userId: '456',
streakId: '789',
timestampISO: '2023-12-06T00:00:00.000Z'
});