Send xAPI Statements
Last updated
Was this helpful?
Last updated
Was this helpful?
This tutorial will walk you through the essential steps to send an xAPI statement to LearnCloud Storage and then read it back. We'll keep it simple so you can get up and running quickly!
Construct a basic xAPI statement.
Send the statement to the LearnCloud xAPI endpoint.
Retrieve and verify the statement you sent.
Understanding Key Concepts:
Your Environment:
You have the DID of the authenticated user.
The default LearnCloud xAPI endpoint is https://cloud.learncard.com/xapi/statements
.
Let's send a statement indicating a user has attempted a challenge in a game.
An xAPI statement has three main parts: an actor
(who did it), a verb
(what they did), and an object
(what they did it to).
✨ Good to know:
DID Usage: For LearnCloud, ensure the userDid
is used in both actor.name
and actor.account.name
.
Verb Selection: Use standard xAPI verb URIs when possible. You can find lists of common verbs online (e.g., on the ADLNet website).
Activity IDs: Make your object.id
URIs unique for each distinct activity. They don't need to be real, live URLs.
Prepare and Send the Statement
We'll use a Workspace
request to send this statement. The key things are the POST
method, correct headers, and the statement in the body.
Check the Response
If successful, the LearnCloud Storage API will typically return an HTTP status like 200 OK
or 204 No Content
. Often, a 200 OK
response to a POST
will include an array containing the unique ID(s) of the statement(s) just stored. Our sendStatement
function logs this.
Now that we've sent a statement, let's try to read statements for that user.
Make the API Call to Read Statements
This will be a GET
request.
Process the Response
The response from a GET
request to the /statements
endpoint will be a JSON object. This object typically contains an array called statements
and optionally a more
property. The more
property provides a URL to fetch the next page of results if pagination is active.
Authentication (X-VP
Header): All requests to the LearnCloud xAPI endpoint must include a valid JWT in the X-VP
header.
Permissions:
Users can only send statements where they are the actor (or have delegated authority).
Users can typically only read statements where they are the actor. The DID in your JWT (X-VP
header) must match the actor's DID you are querying for. A 401 Unauthorized
error often means a DID mismatch or an invalid/expired JWT.
Error Handling: Always check response statuses and handle potential errors from the API or network issues.
Delegated Access: For scenarios where another party needs to read statements, LearnCloud supports a delegated access mechanism using Verifiable Credentials. (See Advanced Topics: Delegated Access for more info).
Congratulations! You've now seen how to send and read basic xAPI statements with LearnCloud.
From here, you can explore:
Sending different types of xAPI statements (e.g., completed
, mastered
, with result
objects).
Connecting these xAPI statements as evidence for Verifiable Credentials.
Happy tracking!
What is xAPI? xAPI (Experience API) is a way to track learning experiences using a simple "Actor - Verb - Object" structure (e.g., "Sarah completed 'Safety Course'"). For a deeper dive, see our core concept page.
What is a DID? A DID (Decentralized Identifier) is a unique identifier for your user. Think of it as a secure, private digital ID. More details can be found on our core concept page.
You have the initialized in your project.
You have obtained a JSON Web Token (JWT) for authentication. This JWT represents the authenticated user (the "actor"). As an example of how to create this JWT, check out the
Voiding Statements: You can invalidate previously sent statements. (See for how).
Using the other examples provided in our .
Implementing more advanced queries to filter and retrieve statements. (See ).