Is there a way to pull more records?

293 Views Asked by At

This is a follow up to a question I posted earlier on parsing xAPI statements. I got the parsing to work and now I'm using the code below to get statements from the ADL LRS and it pulls the first 50 records. Is there a way to specify more records? Thank you.

<!DOCTYPE  html> 
<html lang='en'> 
    <head> 
        <meta charset='UTF-8'> 
        <title>Get my Statements</title> 
        <script type="text/javascript" src="tincan.js"></script> 
    </head> 
    <body> 
        <h1>Get statements</h1> 
        <div id='response'></div>
        <script>
       var tincan = new TinCan (
    {
        recordStores: [
            {
                endpoint: "https://lrs.adlnet.gov/xapi/",
                username: "xapi-tools",
                password: "xapi-tools",
                allowFail: false
            }
        ]
    }
);


    var container =  document.getElementById('response');
    tincan.getStatements({
    'callback': function (err, result) {
        container.innerHTML = (err !== null ? 'ERROR' : parseMyData(result));
    }
});

            parseMyData = function(result) {
            var statements = result.statements;
            var output = '';
            var name,verb,activity;
            for(var i=0;i<statements.length;i++){
                // check the statement for a usable name value
                // (priority = actor.name, actor.mbox, actor.account.name)
                if(statements[i].actor.name != null && statements[i].actor.name != "") {
                    name = statements[i].actor.name
                }else if(statements[i].actor.mbox != null && statements[i].actor.mbox != "") {
                    name = statements[i].actor.mbox
                }else{
                    name = statements[i].actor.account.name
                }
                // check the statement for a usable verb value
                // (priority = verb.display['en-US'], verb.id)
                try{
                    verb = statements[i].verb.display['en-US'];
                }catch(e){
                    verb = statements[i].verb.id;
                }
                // check the activity for a usable value
                // (priority = definition.name['en-US'], id)
                try{
                    activity = statements[i].target.definition.name['en-US'];
                }catch(e){
                    activity = statements[i].target.id;
                }
                output +=   name + ' - ' +
                            verb + ' - ' + 
                            activity +
                            '<br>' 
            }
            return output;
}

        </script> 
    </body> 
</html>
2

There are 2 best solutions below

0
On

Use the code below to request statements with a set limit per page. If you make a request without a limit parameter or a limit of 0, then the maxmimum number of statements allowed by the server will be returned in the first page (this is what you are already doing above).

tincan.getStatements({ params: { limit: 100 }, 'callback': function (err, result) { container.innerHTML = (err !== null ? 'ERROR' : parseMyData(result)); }

See https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#stmtapiget

To get additional pages of statements use the TinCanJS LRS moreStatements method: https://github.com/RusticiSoftware/TinCanJS/blob/master/src/LRS.js#L766

See http://rusticisoftware.github.io/TinCanJS/ for how to create the LRS object.

0
On

More records would be in the request itself. Look at the API documentation, most times there is a parameter you can pass for records to be retrieved.