Pearson
Always Learning

Posted by Wes | about 3 years ago

We are demystifying the Experience API for ourselves and anyone else that wants to follow along. We have covered terminology, Activity Providers and LRS queries. This article will focus on recording xAPI Statements in a LRS.

Background

We have been on a journey to understand the Experience API. We previously explored the following:

Example API Calls

It is time to understand how learning activities are reported to the LRS. We know there is an API involved. We can actually see the API in use with the Golf Example from TinCanAPI.com. The Chrome browser equips us with the tools to watch the API calls. The browser's Developer Tools has a network tab that allows us to monitor what is happening. The request sent during the first few screens of the golf activity make use of API calls for state, batch statements, and single statements. We'll explore each of those next.

State API

The Experience API defines a State API as an Activity Provider work area. The golf example uses this to bookmark the learner’s last location in the content. Let's take a look at this API call:

URL & Method

POST http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/activities/state

Query String Parameters

Parameter Name Parameter Value
stateId bookmarking-data
activityId http://id.tincanapi.com/activity/tincan-prototypes/golf-example
agent
{
    "objectType":"Agent",
    "mbox":"mailto:testjr@beta.projecttincan.com",
    "name":"Test User Jr"
}
registration e168d6a3-46b2-4233-82e7-66b73a179727

Request Headers

Header Name Header Value
Authorization Basic VGVzdFVzZXI6cGFzc3dvcmQ=
Origin http://tincanapi.com
Referer
http://tincanapi.com/wp-content/assets/ClientPrototypes/GolfExample_TCAPI/index.html?
endpoint=http%3A%2F%2Fcloud.scorm.com%2FScormEngineInterface%2FTCAPI%2Fpublic%2F
&auth=Basic%20VGVzdFVzZXI6cGFzc3dvcmQ%3D
&actor=%7B%22mbox%22%3A%22mailto%3Atestjr%40beta.projecttincan.com%22%2C%22name%22%3A%22Test%20User%20Jr%22%2C%22objectType%22%3A%22Agent%22%7D
&registration=e168d6a3-46b2-4233-82e7-66b73a179727

Request Body

{
    "location":0,
    "attemptDuration":3417,
    "attemptComplete":false
}

Response Code

204 No Content

Response Body

N/A

Batch Statement API

The Experience API defines a Statement API with support for batch operations. The golf example uses this operation to capture two statements at activity launch. Let's take a look at this API call:

URL & Method

POST http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/statements

Request Headers

Header Name Header Value
Authorization Basic VGVzdFVzZXI6cGFzc3dvcmQ=
X-Experience-API-Version 1.0.1

Request Body

[
    {
        "id": "1c33b8ff-5234-43c0-a7dd-3fed3a99558f",
        "timestamp": "2015-06-19T20:10:20.386Z",
        "actor": {
            "objectType": "Agent",
            "mbox": "mailto:testjr@beta.projecttincan.com",
            "name": "Test User Jr"
        },
        "verb": {
            "id": "http://adlnet.gov/expapi/verbs/initialized",
            "display": {
                "en-US": "initialized"
            }
        },
        "result": {
            "duration": "PT0S"
        },
        "context": {
            "registration": "e168d6a3-46b2-4233-82e7-66b73a179727",
            "contextActivities": {
                "grouping": [
                    {
                        "id": "http://id.tincanapi.com/activity/tincan-prototypes/golf-example",
                        "objectType": "Activity"
                    },
                    {
                        "id": "http://id.tincanapi.com/activity/tincan-prototypes",
                        "objectType": "Activity"
                    }
                ],
                "category": [
                    {
                        "id": "http://id.tincanapi.com/recipe/tincan-prototypes/golf/1",
                        "objectType": "Activity",
                        "definition": {
                            "type": "http://id.tincanapi.com/activitytype/recipe"
                        }
                    },
                    {
                        "id": "http://id.tincanapi.com/activity/tincan-prototypes/elearning",
                        "objectType": "Activity",
                        "definition": {
                            "type": "http://id.tincanapi.com/activitytype/source",
                            "name": {
                                "en-US": "E-learning course"
                            },
                            "description": {
                                "en-US": "An e-learning course built using the golf prototype framework."
                            }
                        }
                    }
                ]
            }
        },
        "object": {
            "id": "http://id.tincanapi.com/activity/tincan-prototypes/golf-example",
            "objectType": "Activity",
            "definition": {
                "type": "http://adlnet.gov/expapi/activities/course",
                "name": {
                    "en-US": "Golf Example - Tin Can Course"
                },
                "description": {
                    "en-US": "An overview of how to play the great game of golf."
                }
            }
        }
    },
    {
        "id": "6a2190a3-0ce6-41f8-9b40-54335dd12e2a",
        "timestamp": "2015-06-19T20:10:20.386Z",
        "actor": {
            "objectType": "Agent",
            "mbox": "mailto:testjr@beta.projecttincan.com",
            "name": "Test User Jr"
        },
        "verb": {
            "id": "http://adlnet.gov/expapi/verbs/attempted",
            "display": {
                "en-US": "attempted"
            }
        },
        "result": {
            "duration": "PT0S"
        },
        "context": {
            "registration": "e168d6a3-46b2-4233-82e7-66b73a179727",
            "contextActivities": {
                "grouping": [
                    {
                        "id": "http://id.tincanapi.com/activity/tincan-prototypes/golf-example",
                        "objectType": "Activity"
                    },
                    {
                        "id": "http://id.tincanapi.com/activity/tincan-prototypes",
                        "objectType": "Activity"
                    }
                ],
                "category": [
                    {
                        "id": "http://id.tincanapi.com/recipe/tincan-prototypes/golf/1",
                        "objectType": "Activity",
                        "definition": {
                            "type": "http://id.tincanapi.com/activitytype/recipe"
                        }
                    },
                    {
                        "id": "http://id.tincanapi.com/activity/tincan-prototypes/elearning",
                        "objectType": "Activity",
                        "definition": {
                            "type": "http://id.tincanapi.com/activitytype/source",
                            "name": {
                                "en-US": "E-learning course"
                            },
                            "description": {
                                "en-US": "An e-learning course built using the golf prototype framework."
                            }
                        }
                    }
                ]
            }
        },
        "object": {
            "id": "http://id.tincanapi.com/activity/tincan-prototypes/golf-example",
            "objectType": "Activity",
            "definition": {
                "type": "http://adlnet.gov/expapi/activities/course",
                "name": {
                    "en-US": "Golf Example - Tin Can Course"
                },
                "description": {
                    "en-US": "An overview of how to play the great game of golf."
                }
            }
        }
    }
]

Response Code

200 OK

Response Body

[
    "1c33b8ff-5234-43c0-a7dd-3fed3a99558f",
    "6a2190a3-0ce6-41f8-9b40-54335dd12e2a"
]

Single Statement API

The Experience API defines a Statement API with support for single operations. The golf example uses this operation as the user moves through the content. Let's take a look at this API call:

URL & Method

PUT http://cloud.scorm.com/ScormEngineInterface/TCAPI/public/statements

Query String Parameters

Parameter Name Parameter Value
statementId 09d49917-cf3c-4a24-8795-22bb8ade8654

Request Headers

Header Name Header Value
Authorization Basic VGVzdFVzZXI6cGFzc3dvcmQ=
Origin http://tincanapi.com
Referer
http://tincanapi.com/wp-content/assets/ClientPrototypes/GolfExample_TCAPI/Playing/Par.html?
endpoint=http%3A%2F%2Fcloud.scorm.com%2FScormEngineInterface%2FTCAPI%2Fpublic%2F
&auth=Basic%20VGVzdFVzZXI6cGFzc3dvcmQ%3D
&actor=%7B%22mbox%22%3A%22mailto%3Atestjr%40beta.projecttincan.com%22%2C%22name%22%3A%22Test%20User%20Jr%22%2C%22objectType%22%3A%22Agent%22%7D
&registration=e168d6a3-46b2-4233-82e7-66b73a179727
X-Experience-API-Version 1.0.1

Request Body

{
    "id": "09d49917-cf3c-4a24-8795-22bb8ade8654",
    "timestamp": "2015-06-19T18:41:39.106Z",
    "actor": {
        "objectType": "Agent",
        "mbox": "mailto:testjr@beta.projecttincan.com",
        "name": "Test User Jr"
    },
    "verb": {
        "id": "http://adlnet.gov/expapi/verbs/experienced",
        "display": {
            "en-US": "experienced"
        }
    },
    "context": {
        "registration": "e168d6a3-46b2-4233-82e7-66b73a179727",
        "contextActivities": {
            "parent": [
                {
                    "id": "http://id.tincanapi.com/activity/tincan-prototypes/golf-example",
                    "objectType": "Activity"
                }
            ],
            "grouping": [
                {
                    "id": "http://id.tincanapi.com/activity/tincan-prototypes/golf-example",
                    "objectType": "Activity"
                },
                {
                    "id": "http://id.tincanapi.com/activity/tincan-prototypes",
                    "objectType": "Activity"
                }
            ],
            "category": [
                {
                    "id": "http://id.tincanapi.com/recipe/tincan-prototypes/golf/1",
                    "objectType": "Activity",
                    "definition": {
                        "type": "http://id.tincanapi.com/activitytype/recipe"
                    }
                },
                {
                    "id": "http://id.tincanapi.com/activity/tincan-prototypes/elearning",
                    "objectType": "Activity",
                    "definition": {
                        "type": "http://id.tincanapi.com/activitytype/source",
                        "name": {
                            "en-US": "E-learning course"
                        },
                        "description": {
                            "en-US": "An e-learning course built using the golf prototype framework."
                        }
                    }
                }
            ]
        }
    },
    "object": {
        "id": "http://id.tincanapi.com/activity/tincan-prototypes/golf-example/Playing/Par",
        "objectType": "Activity",
        "definition": {
            "type": "http://activitystrea.ms/schema/1.0/page",
            "name": {
                "en-US": "Par"
            },
            "description": {
                "en-US": "An overview of the concept of par in golf."
            }
        }
    }
}

Response Code

204 No Content

Response Body

N/A

What's next?

We now know how the Activity Provider interacts with the Experience API on the LRS to record activity. There is no magic taking place here. The activity statements are triggered by actions taking place in the content. Those trigger locations were selected when the content was created.

We have explored the basics of how xAPI works now. The next article in this series will focus on integration with a LMS. Afterwards, we'll revisit submitting our own xAPI Statements to a LRS.

Feel free to jump ahead to other articles in this series:

Also, definitely check out TinCanAPI.com and ADLNet.gov's xAPI standard for more in-depth details. We are just scratching the surface with this whirlwind tour, and those resources were our reference. We would like to give credit and a BIG THANKS to the maintainers of both!

Tags: 
xAPI
Rating: 

Average: 3 (2 votes)

16558 reads
Always Learning
Pearson