Retrieving a list of Tin Can API statements from SCORM Cloud LRS

1.9k Views Asked by At

I have added a Tin Can course to my LMS and I am successfully able to upload and playback the course so that my statements are being written to the Initial Application Realm LRS. So far so good.

Now I want to be able to retrieve from the LRS a list of all statements that have been written so that I can iterate through these and check for course completion for the signed in user. My statements are being written to the following endpoint:

https://cloud.scorm.com/tc/7QLMQA89WV/

I have tried to query the statements by using the .NET library and the following code:

//Initialize the TinCan Remote LRS for retrieving completion statistics
LRS = new RemoteLRS("https://cloud.scorm.com/tc/7QLMQA89WV/", "<username>", "<pw>");
Version = TinCan.TCAPIVersion.V101;

//Create the TinCan statement to query completed activities for the logged in user
var query = new StatementsQuery();
query.agent = new TinCan.Agent();
query.agent.mbox = "mailto:[email protected]";
query.verbId = new Uri("http://adlnet.gov/expapi/verbs/completed");
query.activityId = new Uri("http://tincanapi.com/GolfExample_TCAPI"); 

This however is returning a list of all statements regardless of verb or activity that have been used. Could there possibly be a bug in the query filter as when using SCORM Cloud I can see the TCAPI query string and when entering the URI of the Verb or Activity here it filters appropriately.

As a means of testing that the statements was being output correctly I also have the following on my view, not sure if this is the best way to get a human readable version of the statement, but I have this output for each statement within my List

<p>@statement.actor.name @statement.verb.display.ToJObject().GetValue("und") '@statement.target.ToJObject(Model.Version)["definition"]["name"]["en-US"]'</p>
2

There are 2 best solutions below

1
On

I recommend using the TinCanJS library. I'll update with a link later, but you should be able yo find it and instructions on Google.

2
On

+1 to Andrew's suggestion for using the library. The reason you are getting the results you are getting is because you are missing the 'X-Experience-API-Version' header which the library adds to all requests appropriately. The lack of a header means the LRS is interpreting the request as a 0.9 version request and unless you've stored statements using that version none will be returned (statements are not down converted).

I know you know where the library is, but for SO's posterity:

http://rusticisoftware.github.io/TinCanJS/

Also note that this will only return the LRS' first page of statements, you'll then need to handle the 'more' URL returned by the LRS to fetch the next page, recursively. TinCanJS provides a simple method for doing that as well.