import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
const response = await trophy.achievements.complete("achievement-key", {
user: {
id: "user-id",
}
});{
"completionId": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"achievement": {
"id": "5100fe51-6bce-6j44-b0hs-bddc4e123682",
"trigger": "api",
"name": "Finish onboarding",
"description": "Complete the onboarding process.",
"badgeUrl": "https://example.com/badge.png",
"key": "finish-onboarding",
"achievedAt": "2021-01-01T00:00:00Z"
},
"points": {
"points-system-key": {
"id": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"name": "XP",
"description": null,
"badgeUrl": null,
"total": 10,
"added": 10,
"awards": [
{
"id": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"awarded": 10,
"date": "2021-01-01T00:00:00Z",
"total": 10,
"trigger": {
"id": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"type": "achievement",
"achievementName": "Finish onboarding",
"points": 10
}
}
]
}
}
}Mark an achievement as completed for a user.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
const response = await trophy.achievements.complete("achievement-key", {
user: {
id: "user-id",
}
});{
"completionId": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"achievement": {
"id": "5100fe51-6bce-6j44-b0hs-bddc4e123682",
"trigger": "api",
"name": "Finish onboarding",
"description": "Complete the onboarding process.",
"badgeUrl": "https://example.com/badge.png",
"key": "finish-onboarding",
"achievedAt": "2021-01-01T00:00:00Z"
},
"points": {
"points-system-key": {
"id": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"name": "XP",
"description": null,
"badgeUrl": null,
"total": 10,
"added": 10,
"awards": [
{
"id": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"awarded": 10,
"date": "2021-01-01T00:00:00Z",
"total": 10,
"trigger": {
"id": "0040fe51-6bce-4b44-b0ad-bddc4e123534",
"type": "achievement",
"achievementName": "Finish onboarding",
"points": 10
}
}
]
}
}
}Unique reference of the achievement as set when created.
The user that completed the achievement. An object with editable user fields.
Show child attributes
The ID of the user in your database. Must be a string.
"user-id"
The user's email address. Required if subscribeToEmails is true.
The name to refer to the user by in emails.
"User"
The user's timezone (used for email scheduling).
"Europe/London"
The user's device tokens, used for push notifications.
The device token.
["token1", "token2"]Whether the user should receive Trophy-powered emails. If false, Trophy will not store the user's email address.
true
Successful operation
The unique ID of the completion.
"0040fe51-6bce-4b44-b0ad-bddc4e123534"
Show child attributes
The unique ID of the achievement.
The name of this achievement.
The trigger of the achievement.
metric, streak, api The description of this achievement.
The URL of the badge image for the achievement, if one has been uploaded.
The key used to reference this achievement in the API (only applicable if trigger = 'api')
The date and time the achievement was completed, in ISO 8601 format. Null if the achievement has not been completed.
The length of the streak required to complete the achievement (only applicable if trigger = 'streak')
The ID of the metric associated with this achievement (only applicable if trigger = 'metric')
The value of the metric required to complete the achievement (only applicable if trigger = 'metric')
The name of the metric associated with this achievement (only applicable if trigger = 'metric')
The user's current streak for the metric, if the metric has streaks enabled.
Show child attributes
The length of the user's current streak.
The frequency of the streak.
daily, weekly, monthly The date the streak started.
The start date of the current streak period.
The end date of the current streak period.
The date the streak will expire if the user does not increment a metric.
Whether this metric event increased the user's streak length.
The number of available streak freezes. Only present if the organization has enabled streak freezes.
The maximum number of streak freezes a user can have. Only present if the organization has enabled streak freezes.
The interval at which the user will earn streak freezes, in days. Only present if the organization has enabled streak freeze auto-earn.
The amount of streak freezes the user will earn per interval. Only present if the organization has enabled streak freeze auto-earn.
A map of points systems by key that were affected by this achievement completion.
Show child attributes
Show child attributes
The ID of the points system
The key of the points system
The name of the points system
The description of the points system
The URL of the badge image for the points system
The maximum number of points a user can be awarded in this points system
The user's total points
Array of trigger awards that added points.
Show child attributes
The ID of the trigger award
The points awarded by this trigger
The date these points were awarded, in ISO 8601 format.
The user's total points after this award occurred.
Show child attributes
The ID of the trigger
The type of trigger
metric, achievement, streak, time, user_creation The points awarded by this trigger.
If the trigger has type 'metric', the name of the metric
If the trigger has type 'metric', the threshold of the metric that triggers the points
If the trigger has type 'streak', the threshold of the streak that triggers the points
If the trigger has type 'achievement', the name of the achievement
If the trigger has type 'time', the unit of time after which to award points
hour, day If the trigger has type 'time', the numer of units of timeUnit after which to award points
The points added by this event.
10
Was this page helpful?