Achievements API
The API for achievements and badges
Add achievements and badges to your app in under an hour. Trophy handles trigger evaluation, badge hosting, progress tracking and rarity calculations so you can focus on the user experience. Start for free, scale to millions of users.
Quickstart
Quickstart: three-call integration
Configure your achievements in the Trophy dashboard first, then use this code to track user progress, check unlocks, and mark completions. The full lifecycle takes three calls.
import { TrophyApiClient } from "@trophyso/node";
const trophy = new TrophyApiClient({ apiKey: process.env.TROPHY_API_KEY });
// 1. Track a metric event (e.g., user completed a lesson)
const eventResponse = await trophy.metrics.event("lessons", {
user: { id: "user-123" },
value: 1,
});
console.log("Event ID:", eventResponse.eventId);
console.log("Lifetime total:", eventResponse.total);
// 2. Check if any achievements unlocked from this event
if (eventResponse.achievements.length > 0) {
for (const achievement of eventResponse.achievements) {
console.log("Unlocked:", achievement.name, "| Badge:", achievement.badgeUrl);
}
}
// 3. Fetch all achievements for a user (for profile display, history, etc.)
const userAchievements = await trophy.users.achievements("user-123");
for (const a of userAchievements) {
console.log(a.name, "| Achieved:", a.achievedAt, "| Rarity:", a.rarity);
}
// 4. Mark an event-triggered achievement complete (e.g., finished onboarding)
const completion = await trophy.achievements.complete("finish-onboarding", {
user: { id: "user-123" },
});
console.log("Completion ID:", completion.completionId);
console.log("Points awarded:", completion.points);Buy vs. build
Why use Trophy's achievements API?
A badge award API looks simple on the surface — store a completion flag, return a URL. The trigger evaluation, deduplication, and progress tracking underneath are where the complexity compounds.
Integration Time
Reliability
Scalability
Ongoing Maintenance
Feature Development
Reference
Objective types
Trophy achievements can trigger in three ways. Configure the objective type and threshold in the dashboard, then send the matching API call.
| Objective type | What triggers it | Example | How you send it |
|---|---|---|---|
| Metric-based | User's lifetime metric total crosses the threshold you set | Wrote 10,000 words | trophy.metrics.event() with the metric key and value |
| Streak-based | User hits a streak milestone | 7-day streak | trophy.metrics.event() on the streak metric (Trophy tracks consecutive days) |
| Event-based | Your code calls the complete endpoint directly | Completed onboarding | trophy.achievements.complete() with the achievement key |
Metric-based
Track incremental progress toward a threshold. Trophy sums events and unlocks the achievement when the total crosses the configured value.
await trophy.metrics.event("words-written", {
user: { id: "user-123" },
value: 500,
});Streak-based
Track daily activity on a streak metric. Trophy handles the consecutive-day logic and unlocks achievements at configured milestones (7 days, 30 days, etc.).
await trophy.metrics.event("daily-practice", {
user: { id: "user-123" },
value: 1,
});Event-based
Trigger an achievement directly when a user completes a one-time action.
await trophy.achievements.complete("finish-onboarding", {
user: { id: "user-123" },
});Endpoints
Achievement endpoints
Use Trophy's achievement tracking API to award badges automatically from metric events, streak milestones, or direct API calls. Progress is evaluated in real time with every event you send.
Send a metric event to track user activity and power achievements.
Path Parameters
keystringrequiredUnique reference of the metric as set when created.
Request Body
userUserrequiredThe user that triggered the event (must include id).
valuenumberrequiredThe value to add to the user's current total for the given metric.
Response
eventIdstringUnique identifier for the created event.
totalnumberThe user's new total for this metric.
achievementsAchievement[]New achievements unlocked by this event.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
// Track a user event
await trophy.metrics.event("lessons", {
user: {
id: "user-123"
},
value: 1
}
);
// This single event:
// - Records user activity
// - Evaluates achievement triggers
// - Returns new unlocked achievements
Get a user's achievements. By default returns only completed achievements.
Path Parameters
idstringrequiredID of the user.
Query Parameters
includeIncompletestringSet to "true" to include incomplete achievements.
Response
keystringUnique key of the achievement.
namestringDisplay name of the achievement.
achievedAtISO 8601When the achievement was completed (null if incomplete).
badgeUrlstringURL of the achievement badge image.
raritynumberPercentage of users who have completed this achievement.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
// Fetch all achievements for a user
const achievements = await trophy.users
.achievements("user-123");
// Response:
// [
// {
// key: "completed-onboarding",
// name: "Completed Onboarding",
// trigger: "api",
// achievedAt: "2021-01-01T00:00:00Z",
// badgeUrl: "https://...",
// rarity: 50
// }
// ]Mark an achievement as completed for a user. Use for API-triggered achievements.
Path Parameters
keystringrequiredUnique reference of the achievement as set when created.
Request Body
userUserrequiredThe user that completed the achievement (must include id).
Response
completionIdstringUnique identifier for the completion.
achievementAchievementThe completed achievement with badge URL and metadata.
pointsobjectPoints awarded for this completion, keyed by points system.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
// Complete an achievement for a user
await trophy.achievements.complete(
"finish-onboarding",
{
user: { id: "user-123" }
}
);
// Returns completionId, achievement
// object, and any points awardedLightning-fast integration
Simple APIs you'll love
Use our pre-built gamification platform to effortlessly build engaging user experiences. Get a team that's 100% focused on engagement.
- Type-safe SDKs.
- We spend time worrying about abstractions and let you focus on what matters: building a great experience for your users.
- Intuitive documentation.
- Documentation built by developers for developers. Get started in minutes, not hours.
- Effortless debugging.
- Get to the root of the issue fast with detailed event logs and error messages.
// Fetch and display achievements
const achievements = await trophy.users
.achievements("user-123");
// Display badges
for (const a of achievements) {
console.log(a.name, a.badgeUrl);
}
Gamification UI library
Pixel-perfect achievements UI components
Use our open-source gamification UI components as the foundation for your design system. Customize as you see fit. Designed to work perfectly with the Trophy API.
- One-command install
- Add any component to your project with a single CLI command. No extra dependencies to manage.
- Fully customizable
- Every component lives in your codebase. Tweak styles, layout, and behavior to match your brand.
- Open-source.
- MIT licensed and community-driven. Use in personal projects or production apps without restrictions.
Built for production workloads
Reliable infrastructure designed for performance at scale.
- Uptime SLA
- 99.99%
- p95 API Latency
- 200ms
- Monthly API Requests
- 150M
- Users Tracked
- 1M+
FAQ
Frequently asked questions
Have a different question and can’t find the answer you’re looking for? Send us an email.
Get started