How to Query an LRS to get xAPI Statements

30 June 2016 by Ryan Smith

So you’ve got your LRS set up, and it’s doing a great job of storing your activity data, and your dashboards are looking great. But how do you actually gain more detailed insights into the data? Well, in this post we’ll be having a quick look at ways in which you can query xAPI statements – or more specifically the Statement API.

Before you get started, you’ll need a suitable API query builder such as Postman.  You might also find it useful to watch along with this video if you’re unfamiliar with the interface.

Querying the Statement API

The statement API allows you to create statements and retrieve one or many statements that you previously created.

Creating a Statement

You can create a statement with the following request.

POST https://v2.learninglocker.net/v1/data/xAPI/statements

Headers

Authorization:Basic YOUR_BASIC_AUTH

X-Experience-API-Version:1.0.0

Content-Type:application/json

Body

{    “actor”:{        “objectType”:”Agent”,        “name”:”John Smith”,        “account”:{            “name”:”123″,            “homePage”:”https://www.example.com/users/”        }    },    “verb”:{        “id”:”https://adlnet.gov/expapi/verbs/completed”,        “display”:{            “en-GB”:”completed”        }    },    “object”:{        “objectType”:”Activity”,        “id”:”https://www.example.com/activities/1″    } }

Response

[

“af2f7cc3-5b4f-4032-8449-6edaf8f98fb7”

]

Querying Known Statement IDs

Using the statement ID that the LRS provides you in response to creating a statement, you can query the statement from the API, with the following request.

GET https://v2.learninglocker.net/v1/data/xAPI/statements?statementId=af2f7cc3-5b4f-4032-8449-6edaf8f98fb7

Headers

Authorization:Basic YOUR_BASIC_AUTH

X-Experience-API-Version:1.0.0

Multiple Statement Queries

If you want to query multiple statements, you can create the following request.

GET https://v2.learninglocker.net/v1/data/xAPI/statements?verb=https://adlnet.gov/expapi/verbs/completed

Headers

Authorization:Basic YOUR_BASIC_AUTH

X-Experience-API-Version:1.0.0

Additional xAPI Queries

So there you have just 3 example queries that you can run on your xAPI data. For further details on which parts of a statement can be queried, check out the official specification documentation.

Next up, we’ll be taking a look at how to void xAPI Statements.

For more practical tips on the xAPI, check out our free Learning Technology Manager’s Guide to xAPI

blank
Ryan Smith
Software Development Team Lead

Starting as a placement student in 2014, Ryan re-joined the Learning Locker team after graduating from Oxford Brookes University where he won the John Birch prize for the highest grade average in the University.

From his minimalist desk, Ryan leads the Learning Locker team and consults with people on all things xAPI to conscientiously craft products and services that sustain and evolve training and performance.

When he’s not swimming or injuring himself on the cricket field, Ryan enjoys playing funny (and usually inappropriate) games with his family.

View more from Ryan Smith
blank
Read more about Learning Pool
Visit our Learn and Connect section

Get a free demo

Get in touch to find out how we can help

Start your learning journey

Get started by telling us what you need and one of our team will be in touch very soon.