> For the complete documentation index, see [llms.txt](https://developerdocs.instructure.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developerdocs.instructure.com/services/canvas/external-tools/file.xapi.md).

# xAPI

## xAPI with LTI tools

Canvas has implemented a small piece of xAPI (Tin Can API). [Go here to learn more about xAPI](https://www.adlnet.gov/experience-api).

An external tool can ask for an xAPI callback URL, and then POST back an interaction activity to Canvas. This will update the activity time for the user in Canvas, and add a page view for that tool. Page views will show up in the course analytics section as activity.

## Instructions

* The external tool should use the substitution parameter of `$Canvas.xapi.url` in its LTI launch parameters.
* The tool can then save the url value that is given when launched.
* The tool POSTs to that url and signs the request with the LTI OAuth parameters.
* The content-type should be `application/json`, with an xAPI body.
  * Here are some good examples: [Example Statements](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#Appendix2A)
* The `object.id` will be logged as the page view URL.
* `result.duration` must be an [ISO 8601 duration](http://en.wikipedia.org/wiki/ISO_8601#Durations) if supplied.
  * Canvas page views cap at 5 minutes for now. So any value greater than that is just logged as 5 minutes.

Here is an example of the minimum JSON that would log 3 minutes of activity for `http://example.com`:

```json
{
  "id": "12345678-1234-5678-1234-567812345678",
  "actor": {
    "account": {
      "homePage": "http://www.instructure.com/",
      "name": "unique_name_for_user_of_some_kind_maybe_lti_user_id"
    }
  },
  "verb": {
    "id": "http://adlnet.gov/expapi/verbs/interacted",
    "display": {
      "en-US": "interacted"
    }
  },
  "object": {
    "id": "http://example.com/"
  },
  "result": {
    "duration": "PT3M0S"
  }
}
```

***

This documentation is generated directly from the Canvas LMS source code, available [on Github](https://github.com/instructure/canvas-lms).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developerdocs.instructure.com/services/canvas/external-tools/file.xapi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
