When dealing with large statement volumes or statements with extensive data in extensions, you can use the following techniques to retrieve more manageable subsets of data.
Basic Query Parameters
The xAPI API supports several query parameters to limit and filter your results:
// Basic query with filtering
const queryParams = new URLSearchParams({
agent: JSON.stringify(actor),
limit: "10", // Limit to 10 results
since: "2024-03-01T00:00:00Z", // Only statements after this date
until: "2024-03-31T23:59:59Z", // Only statements before this date
verb: "http://adlnet.gov/expapi/verbs/completed" // Only specific verb
});
const response = await fetch(`${endpoint}/statements?${queryParams}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-Experience-API-Version': '1.0.3',
'X-VP': jwt
}
});
Key Filtering Parameters
Parameter
Description
Example
limit
Maximum number of statements to return
limit=20
since
ISO 8601 date to filter statements after
since=2024-03-01T00:00:00Z
until
ISO 8601 date to filter statements before
until=2024-03-31T23:59:59Z
verb
Filter by verb ID
verb=http://adlnet.gov/expapi/verbs/completed
activity
Filter by activity ID
activity=http://yourgame.com/activities/level-1
ascending
Return in ascending order (oldest first)
ascending=true
Using Pagination
For very large datasets, implement pagination:
// First page
let more = "";
const getPage = async (more) => {
const url = more || `${endpoint}/statements?${queryParams.toString()}`;
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-Experience-API-Version': '1.0.3',
'X-VP': jwt
}
});
const data = await response.json();
// Process the statements
processStatements(data.statements);
// Check if there are more pages
return data.more || null;
};
// Initial request
more = await getPage();
// Get next page if available
if (more) {
more = await getPage(more);
}
Reducing Statement Size
If dealing with extremely large data in extensions:
Reference Instead of Embed: Store large data elsewhere and include a reference URL in your statement: