Example: Creating a submission
It all starts with a Submission
, a Submission
is a chunk of data submitted by the user that can be aggregated and used to evaluate targets which might then lead to a user being awarded badges and XP.
Creating a submission is easy and can be accomplised with a simplePOST
request. In this example we create a new submission using the following propertiessubmissionType
, clientId
and data
A successful request to create a submission will respond with the newly created submission, an array of targets and badges that the submission has met the conditions of, as well as the totalXP earned from that submission.
- Name
submissionType
- Type
- string
- Description
Slug of the submission type that can be defined in the developer dashboard. The schema defined on this submission type will the be used to validate the data payload.
- Name
data
- Type
- JSON
- Description
The shape of this is entirely upto you and must adhere to the schema defined in the
submissionType
Create Submission Request
const data = {
mood: 8,
sleep: 7,
food: 6,
hyhdration: 7
};
const result = await fetch('...api/v2/submissions', {
method: 'POST',
headers: {
Authorization: 'Bearer <token>'
},
data: JSON.stringify({
clientId: '65dfcee9-7f4c-46c4',
submissionType: 'mood-tracker',
data
})
});
Create Submission Response
const resposnse = {
submission: {
"documentId": "bzzlpqp9nfes8yygvb33sstz",
"createdAt": "2025-05-02T22:01:46.717Z",
"updatedAt": "2025-05-02T22:01:46.717Z",
"date": "2025-08-06",
"data": {
"mood": 8,
"sleep": 7,
"food": 6,
"hyhdration": 7
}
},
targets: [
{
"id": 1,
"documentId": "pdfx7woqmj684qiawyk5e72j",
"streak": 5,
"longestStreak": 5,
"earnedXP": 500,
"target": {
"documentId": "mfjpj66t7xtlmtvfvap0bctb",
"title": "Good mood",
"description": "Awarded when a user uploads a submission with a mood above 5",
"expression": "submission.mood > 5",
"duration": "day",
"xpValue": 100,
"scope": "user",
"type": "goal",
"slug": "good-mood",
"context": "submission"
},
}
],
badges: [
{
"id": 2,
"documentId": "x377e40yzozy1m8c8yy5bm8c",
"name": "Professional",
"slug": "professional",
"description": "Professional badge is awarded when you reach 10000 XP",
"xpValue": 1000,
"type": "milestone",
"expression": "getXP() > 1000",
"streak": null,
"milestone": null,
"icon": null,
}
],
earnedXP: 1100
}