@edpire/sdk/client subpath exports a typed Node.js API client. Zero browser dependencies. Uses native fetch (Node 18+).
Installation
npm install @edpire/sdk
Setup
import { EdpireClient } from "@edpire/sdk/client"
const client = new EdpireClient({
apiKey: process.env.EDPIRE_API_KEY!,
baseUrl: "https://app.edpire.com", // default, can be omitted
})
Assessments
// List with filters
const { items, total } = await client.getAssessments({
status: "published",
page: 1,
limit: 20,
})
// Bulk fetch by IDs (max 50)
const { items } = await client.getAssessments({
ids: ["id1", "id2", "id3"],
})
// Single assessment with exercises
const assessment = await client.getAssessment("assessment-uuid")
// assessment.exercises[].questions[].content_ast
Submit for grading (headless)
const result = await client.submit("assessment-uuid", {
learner_ref: "user-123",
answers: {
exerciseAnswers: [
{
exerciseId: "ex-1",
questionAnswers: [
{
questionId: "q-1",
answers: [{ nodeId: "n1", type: "choiceSet", value: ["opt_a"] }],
},
],
},
],
},
})
console.log(result.score, result.max_score, result.passed)
// result.exercise_results[].question_results[].feedback
Check a single question
const check = await client.checkQuestion("assessment-uuid", {
exercise_id: "ex-1",
question_id: "q-1",
answers: [{ nodeId: "n1", type: "choiceSet", value: ["opt_a"] }],
learner_ref: "user-123",
session_id: "attempt-uuid", // generate once per attempt
})
if (check.correct) {
// success
} else {
// pass check.feedback to the question renderer
}
Submissions & learner history
// Full submission with per-question results
const submission = await client.getSubmission("submission-uuid")
// All submissions for a learner
const { items } = await client.getLearnerResults("user-123", {
page: 1,
limit: 50,
})
Collections
const { items: collections } = await client.getCollections()
const detail = await client.getCollection("collection-uuid")
// detail.items[].assessment
const { items: results } = await client.getCollectionResults("collection-uuid")
Webhooks
// Register (secret shown once — store it)
const webhook = await client.registerWebhook(
"https://yourplatform.com/webhooks/edpire",
["submission.graded", "assessment.published", "assessment.content_updated"]
)
console.log(webhook.secret)
// List & delete
const webhooks = await client.listWebhooks()
await client.deleteWebhook("webhook-uuid")
Mint embed token
// Server-side only — pass token to browser for EdpireAssessment.mount()
const embed = await client.mintEmbedToken("assessment-uuid", "user-123")
// embed.token, embed.expires_at
Error handling
All methods throwEdpireError on non-2xx responses:
import { EdpireClient, EdpireError } from "@edpire/sdk/client"
try {
const assessment = await client.getAssessment("bad-id")
} catch (err) {
if (err instanceof EdpireError) {
console.log(err.status) // 404
console.log(err.message) // "Assessment not found"
}
}
Custom fetch (testing / edge runtimes)
const client = new EdpireClient({
apiKey: "test-key",
baseUrl: "http://localhost:3001",
fetch: customFetch, // injectable for testing or Cloudflare Workers
})