Skip to content

Write a statement

Oliver Pincus edited this page Jan 30, 2019 · 16 revisions

As a xAPI statement is a JSON object sent to the Learning Record Store (LRS), there are many options to write a statement.

xAPI Lab Form

  1. Go to https://adlnet.github.io/xapi-lab/.
  2. Fill out the form
  3. Get the statement from the Statement Editor box.
{
    "actor": {
        "account": {
            "name": "Guest"
        },
        "objectType": "Agent"
    },
    "verb": {
        "id": "http://adlnet.gov/expapi/verbs/launched",
        "display": {
            "en-US": "launched"
        }
    },
    "object": {
        "id": "https://xapistatementbox.github.io",
        "definition": {
            "description": {
                "en-US": "Demo"
            }
        },
        "objectType": "Activity"
    }
}

Code (xAPI Wrapper/JavaScript)

  1. Create a HTML page.
  2. Download script from https://github.com/adlnet/xAPIWrapper and embed.
<script type="text/javascript" src="js/xapiwrapper.min.js"></script>
  1. Add JavaScript to create statement.
    //define the xapi statement being sent from scratch
    var statement = new ADL.XAPIStatement(
    new ADL.XAPIStatement.Agent(ADL.XAPIWrapper.hash('mailto:guest@URL.url'), 'Guest'),
    new ADL.XAPIStatement.Verb('http://adlnet.gov/expapi/verbs/launched', 'launched'),
    new ADL.XAPIStatement.Activity('https://xapistatementbox.github.io', 'Demo')
    );
  1. Get string from the JSON object.

    JSON.stringify(statement, null, 4)

The above example writes this statement:

{
"actor": {
    "objectType": "Agent",
    "name": "Guest",
    "mbox_sha1sum": "eebc17aa5e5dbf9a5a291d47063c6d296f3ebd62"
},
"verb": {
    "id": "http://adlnet.gov/expapi/verbs/launched",
    "display": {
        "en-US": "launched"
    }
},
"object": {
    "objectType": "Activity",
    "id": "https://xapistatementbox.github.io",
    "definition": {
        "name": {
            "en-US": "Demo"
        }
    }
}
}

Editor

  1. Open a text editor.
  2. Write the statement from scratch as JSON.
Clone this wiki locally