### Get Launch Data Methods Source: https://context7.com/xapijs/xapi-demo/llms.txt Methods to parse and retrieve launch parameters, useful for integrating with Learning Management Systems (LMS) or adhering to the xAPI Launch specification. ```APIDOC ## Get Launch Data Methods ### getSearchQueryParamsAsObject #### Description Parses URL query parameters from the current location, useful for extracting launch parameters from LMS systems. #### Method `static getSearchQueryParamsAsObject(url: string): object` #### Parameters ##### Query Parameters - **url** (string) - Required - The URL to parse query parameters from. #### Response Example ```typescript const params = XAPI.getSearchQueryParamsAsObject(location.href); // Returns: { endpoint: "https://...", auth: "Basic ...", actor: "{...}" } ``` ### getTinCanLaunchData #### Description Retrieves TinCan launch parameters from URL query string, commonly used when content is launched from an LMS. #### Method `static getTinCanLaunchData(): object` #### Response Example ```typescript const tinCanLaunchData = XAPI.getTinCanLaunchData(); // Returns: { endpoint: "https://...", auth: "Basic ...", actor: { objectType: "Agent", ... } } if (tinCanLaunchData.endpoint) { const xapi = new XAPI({ endpoint: tinCanLaunchData.endpoint, auth: tinCanLaunchData.auth }); } ``` ### getXAPILaunchData #### Description Asynchronously retrieves xAPI launch data according to the xAPI Launch specification. #### Method `static getXAPILaunchData(): Promise` #### Response Example ```typescript XAPI.getXAPILaunchData() .then((xAPILaunchData) => { console.log("Launch data:", xAPILaunchData); // Returns: { endpoint: "https://...", ... } }) .catch((error) => { console.error("Failed to get launch data:", error); }); ``` ``` -------------------------------- ### Get Activity Definition with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves the complete definition of an activity from the Learning Record Store (LRS). Requires the activity ID. ```typescript xapi.getActivity({ activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo" }) .then((result) => { console.log("Activity:", result.data); // Returns: { id: "https://...", definition: { name: {...}, description: {...}, type: "..." } } }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Get All Activity Profile IDs with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves a list of all profile IDs associated with a specific activity. Requires the activity ID. ```typescript xapi.getActivityProfiles({ activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo" }) .then((result) => { console.log("Activity Profile IDs:", result.data); // Returns: ["course-structure", "metadata", "analytics"] }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Get Specific Activity Profile Document with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves a specific activity profile document by its ID. Requires the activity ID and the profile ID. ```typescript xapi.getActivityProfile({ activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo", profileId: "course-structure" }) .then((result) => { console.log("ETag:", result.headers.etag); console.log("Activity Profile:", result.data); // Returns: { modules: [...], totalDuration: "PT2H30M" } }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Get All Agent Profile IDs with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves a list of all profile IDs associated with a specific agent. Requires agent details. ```typescript xapi.getAgentProfiles({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" } }) .then((result) => { console.log("Profile IDs:", result.data); // Returns: ["preferences", "achievements", "settings"] }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Get LRS About Information with TypeScript Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves information about the Learning Record Store (LRS), including supported xAPI versions and extensions. This method returns a Promise that resolves with the LRS information or rejects with an error. ```typescript xapi.getAbout() .then((result) => { console.log("LRS Info:", result.data); // Returns: { version: ["1.0.0", "1.0.1", "1.0.2", "1.0.3"], extensions: {...} } }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Get Specific Agent Profile Document with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves a specific agent profile document by its ID. Requires agent details and the profile ID. ```typescript xapi.getAgentProfile({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" }, profileId: "preferences" }) .then((result) => { console.log("ETag:", result.headers.etag); console.log("Profile:", result.data); // Returns: { language: "en", theme: "dark" } }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Get All State IDs (TypeScript) Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves a list of all state IDs associated with a specific agent and activity, optionally filtered by a registration. This is useful for discovering what state data exists for a given context. ```typescript xapi.getStates({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" }, activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo", registration: "ec531277-b57b-4c15-8d91-d292c5b2b8f7" }) .then((result) => { console.log("State IDs:", result.data); // Returns: ["bookmark", "progress", "preferences"] }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Get Specific State Document (TypeScript) Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves the content of a specific state document identified by its state ID, agent, activity, and optionally, registration. The response includes the ETag for concurrency control and the state data itself. ```typescript xapi.getState({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" }, activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo", stateId: "bookmark", registration: "ec531277-b57b-4c15-8d91-d292c5b2b8f7" }) .then((result) => { console.log("ETag:", result.headers.etag); console.log("State:", result.data); // Returns: { page: 5, section: "chapter2" } }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### XAPI Client Initialization Source: https://context7.com/xapijs/xapi-demo/llms.txt Initializes a new XAPI client instance with the LRS endpoint URL, authentication credentials, and the desired xAPI specification version. ```APIDOC ## XAPI Client Initialization ### Description Creates a new XAPI client instance with endpoint URL, authentication credentials, and xAPI specification version. ### Method `new XAPI(options)` ### Parameters #### Request Body - **endpoint** (string) - Required - The URL of the LRS endpoint. - **auth** (string) - Required - Authentication credentials (e.g., 'Basic base64EncodedCredentials'). - **version** (string) - Optional - The xAPI specification version (e.g., "1.0.0", "1.0.1"). Defaults to the latest supported version. ### Request Example ```typescript import XAPI from "@xapi/xapi"; import { Versions } from "@xapi/xapi/dist/types/constants"; const xapi = new XAPI({ endpoint: "https://lrs.example.com/xapi/", auth: "Basic " + btoa("username:password"), version: "1.0.1" as Versions // Options: "1.0.0", "1.0.1", "1.0.2", "1.0.3" }); ``` ``` -------------------------------- ### Initialize xAPI Client with TypeScript Source: https://context7.com/xapijs/xapi-demo/llms.txt Creates a new XAPI client instance using the @xapi/xapi library. Requires endpoint URL, authentication credentials, and optionally the xAPI specification version. The version can be one of the supported constants. ```typescript import XAPI from "@xapi/xapi"; import { Versions } from "@xapi/xapi/dist/types/constants"; const xapi = new XAPI({ endpoint: "https://lrs.example.com/xapi/", auth: "Basic " + btoa("username:password"), version: "1.0.1" as Versions // Options: "1.0.0", "1.0.1", "1.0.2", "1.0.3" }); ``` -------------------------------- ### Create Activity Profile Source: https://context7.com/xapijs/xapi-demo/llms.txt Creates a new activity profile document. If a profile with the same ID already exists, it will be merged with the new data. ```APIDOC ## POST /xapi/activities/profile ### Description Creates a new activity profile document, merging with existing data if present. ### Method POST ### Endpoint /xapi/activities/profile ### Parameters #### Query Parameters - **activityId** (string) - Required - The ID of the activity. - **profileId** (string) - Required - The ID of the profile. #### Request Body - **profile** (object) - Required - The profile data to be stored. - **etag** (string) - Optional - The ETag of the profile to match for conditional requests. - **matchHeader** (string) - Optional - The header to use for conditional requests (e.g., 'If-None-Match'). ### Request Example ```json { "activityId": "https://www.xapijs.dev/activity/xapijs/xapi-demo", "profileId": "course-structure", "profile": { "modules": ["intro", "chapter1", "chapter2"], "totalDuration": "PT2H30M" }, "etag": "\"def456\"", "matchHeader": "If-None-Match" } ``` ### Response #### Success Response (200 OK) - **data** (object) - The response data, typically confirming the creation or update. #### Response Example ```json { "message": "Activity profile created successfully." } ``` ``` -------------------------------- ### About Resource Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves information about the Learning Record Store (LRS), including supported xAPI versions and extensions. ```APIDOC ## About Resource ### getAbout #### Description Retrieves information about the LRS, including supported xAPI versions. #### Method `xapi.getAbout(): Promise` #### Response ##### Success Response (200) - **data** (object) - An object containing LRS information, including `version` (array of strings) and `extensions` (object). #### Response Example ```typescript xapi.getAbout() .then((result) => { console.log("LRS Info:", result.data); // Returns: { version: ["1.0.0", "1.0.1", "1.0.2", "1.0.3"], extensions: {...} } }) .catch((error) => { console.error("Error:", error); }); ``` ``` -------------------------------- ### Activity Profile Resource API Source: https://context7.com/xapijs/xapi-demo/llms.txt Endpoints for managing activity profile documents, including retrieval of all profile IDs and specific profile documents. ```APIDOC ## GET /xapi/activities/profile ### Description Retrieves all profile IDs associated with a given activity. ### Method GET ### Endpoint `/xapi/activities/profile` ### Parameters #### Query Parameters - **activityId** (string) - Required - The ID of the activity for which to retrieve profile IDs. ### Request Example ```json { "activityId": "https://www.xapijs.dev/activity/xapi-demo" } ``` ### Response #### Success Response (200 OK) - **data** (array) - A list of profile IDs (strings). #### Response Example ```json ["course-structure", "metadata", "analytics"] ``` ``` ```APIDOC ## GET /xapi/activities/profile/{profileId} ### Description Retrieves a specific activity profile document. ### Method GET ### Endpoint `/xapi/activities/profile/{profileId}` ### Parameters #### Path Parameters - **profileId** (string) - Required - The ID of the profile to retrieve. #### Query Parameters - **activityId** (string) - Required - The ID of the activity associated with the profile. ### Request Example ```json { "activityId": "https://www.xapijs.dev/activity/xapi-demo", "profileId": "course-structure" } ``` ### Response #### Success Response (200 OK) - **data** (object) - The activity profile document. - **headers.etag** (string) - The ETag of the retrieved profile. #### Response Example ```json { "modules": [ { "id": "module1", "title": "Introduction" } ], "totalDuration": "PT2H30M" } ``` ``` -------------------------------- ### Create Agent Profile Document with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Creates a new agent profile document, merging with existing data if the profile already exists. Requires agent details, profile ID, the profile data, and optionally an etag and matchHeader. ```typescript xapi.createAgentProfile({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" }, profileId: "preferences", profile: { language: "en", theme: "dark", notifications: true }, etag: '"xyz789"', matchHeader: "If-Match" }) .then((result) => { console.log("Profile created:", result.data); }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Set Activity Profile Source: https://context7.com/xapijs/xapi-demo/llms.txt Replaces an existing activity profile document entirely with the new provided data. ```APIDOC ## PUT /xapi/activities/profile ### Description Replaces an existing activity profile document entirely with the new provided data. ### Method PUT ### Endpoint /xapi/activities/profile ### Parameters #### Query Parameters - **activityId** (string) - Required - The ID of the activity. - **profileId** (string) - Required - The ID of the profile. #### Request Body - **profile** (object) - Required - The new profile data to replace the existing one. - **etag** (string) - Optional - The ETag of the profile to match for conditional requests. - **matchHeader** (string) - Optional - The header to use for conditional requests (e.g., 'If-Match'). ### Request Example ```json { "activityId": "https://www.xapijs.dev/activity/xapijs/xapi-demo", "profileId": "course-structure", "profile": { "modules": ["intro", "chapter1", "chapter2", "quiz"], "totalDuration": "PT3H" }, "etag": "\"def456\"", "matchHeader": "If-Match" } ``` ### Response #### Success Response (200 OK) - **data** (object) - The response data, typically confirming the update. #### Response Example ```json { "message": "Activity profile updated successfully." } ``` ``` -------------------------------- ### Agent Profile API Source: https://context7.com/xapijs/xapi-demo/llms.txt Endpoints for managing agent profile documents, including retrieval, creation, updating, and deletion. ```APIDOC ## GET /xapi/agents/profile ### Description Retrieves all profile IDs associated with a given agent. ### Method GET ### Endpoint `/xapi/agents/profile` ### Parameters #### Query Parameters - **agent** (object) - Required - The agent for whom to retrieve profile IDs. ### Request Example ```json { "agent": { "objectType": "Agent", "mbox": "mailto:learner@example.com" } } ``` ### Response #### Success Response (200 OK) - **data** (array) - A list of profile IDs (strings). #### Response Example ```json ["preferences", "achievements", "settings"] ``` ``` ```APIDOC ## GET /xapi/agents/profile/{profileId} ### Description Retrieves a specific agent profile document. ### Method GET ### Endpoint `/xapi/agents/profile/{profileId}` ### Parameters #### Path Parameters - **profileId** (string) - Required - The ID of the profile to retrieve. #### Query Parameters - **agent** (object) - Required - The agent associated with the profile. ### Request Example ```json { "agent": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "profileId": "preferences" } ``` ### Response #### Success Response (200 OK) - **data** (object) - The profile document. - **headers.etag** (string) - The ETag of the retrieved profile. #### Response Example ```json { "language": "en", "theme": "dark" } ``` ``` ```APIDOC ## PUT /xapi/agents/profile/{profileId} ### Description Creates or updates an agent profile document. If the profile exists, it will be merged with the existing data. If it does not exist, it will be created. ### Method PUT ### Endpoint `/xapi/agents/profile/{profileId}` ### Parameters #### Path Parameters - **profileId** (string) - Required - The ID of the profile to create or update. #### Query Parameters - **agent** (object) - Required - The agent associated with the profile. - **etag** (string) - Optional - The ETag of the profile to update (used for optimistic concurrency control). - **matchHeader** (string) - Optional - Specifies the condition for the update (e.g., "If-Match" or "If-None-Match"). ### Request Body - **profile** (object) - Required - The profile data to be stored. ### Request Example ```json { "agent": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "profileId": "preferences", "profile": { "language": "en", "theme": "dark", "notifications": true }, "etag": "\"xyz789\"", "matchHeader": "If-Match" } ``` ### Response #### Success Response (200 OK or 204 No Content) - **data** (object) - The updated or created profile document (if returned). #### Response Example ```json { "language": "en", "theme": "dark", "notifications": true } ``` ``` ```APIDOC ## POST /xapi/agents/profile/{profileId} ### Description Replaces an existing agent profile document entirely with new data. This is a full replacement operation. ### Method POST ### Endpoint `/xapi/agents/profile/{profileId}` ### Parameters #### Path Parameters - **profileId** (string) - Required - The ID of the profile to replace. #### Query Parameters - **agent** (object) - Required - The agent associated with the profile. - **etag** (string) - Optional - The ETag of the profile to replace (used for optimistic concurrency control). - **matchHeader** (string) - Optional - Specifies the condition for the replacement (e.g., "If-Match"). ### Request Body - **profile** (object) - Required - The new profile data. ### Request Example ```json { "agent": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "profileId": "preferences", "profile": { "language": "fr", "theme": "light", "notifications": false }, "etag": "\"xyz789\"", "matchHeader": "If-Match" } ``` ### Response #### Success Response (200 OK or 204 No Content) - **data** (object) - The replaced profile document (if returned). #### Response Example ```json { "language": "fr", "theme": "light", "notifications": false } ``` ``` ```APIDOC ## DELETE /xapi/agents/profile/{profileId} ### Description Deletes a specific agent profile document. ### Method DELETE ### Endpoint `/xapi/agents/profile/{profileId}` ### Parameters #### Path Parameters - **profileId** (string) - Required - The ID of the profile to delete. #### Query Parameters - **agent** (object) - Required - The agent associated with the profile. - **etag** (string) - Optional - The ETag of the profile to delete (used for optimistic concurrency control). ### Request Example ```json { "agent": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "profileId": "preferences", "etag": "\"xyz789\"" } ``` ### Response #### Success Response (204 No Content) - **No response body** #### Response Example (No content) ``` -------------------------------- ### Create Activity Profile with xAPI.js Source: https://context7.com/xapijs/xapi-demo/llms.txt Creates a new activity profile document. If a profile with the same ID already exists, it will be merged with the new data. This function requires the activity ID, profile ID, the profile data itself, and optionally an ETag for conditional requests. ```typescript xapi.createActivityProfile({ activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo", profileId: "course-structure", profile: { modules: ["intro", "chapter1", "chapter2"], totalDuration: "PT2H30M" }, etag: '"def456"', matchHeader: "If-None-Match" }) .then((result) => { console.log("Activity profile created:", result.data); }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### State Resource API Source: https://context7.com/xapijs/xapi-demo/llms.txt Endpoints for managing state data associated with agents and activities. ```APIDOC ## GET /xapi/state ### Description Retrieves all state IDs for a given agent and activity. ### Method GET ### Endpoint /xapi/state ### Parameters #### Query Parameters - **agent** (object) - Required - The agent to retrieve states for. - **activityId** (string) - Required - The activity ID to retrieve states for. - **registration** (string) - Optional - The registration ID to filter states by. ### Response #### Success Response (200) - **stateIds** (array) - An array of state IDs. #### Response Example ```json ["bookmark", "progress", "preferences"] ``` ## GET /xapi/state/{stateId} ### Description Retrieves a specific state document. ### Method GET ### Endpoint /xapi/state/{stateId} ### Parameters #### Query Parameters - **agent** (object) - Required - The agent the state belongs to. - **activityId** (string) - Required - The activity ID the state belongs to. - **stateId** (string) - Path Parameter - Required - The ID of the state document to retrieve. - **registration** (string) - Optional - The registration ID to filter states by. ### Response #### Success Response (200) - **ETag** (string) - The ETag of the state document. - **state** (object) - The state document data. #### Response Example ```json { "page": 5, "section": "chapter2" } ``` ## POST /xapi/state/{stateId} ### Description Creates a new state document, merging with existing data if present. ### Method POST ### Endpoint /xapi/state/{stateId} ### Parameters #### Query Parameters - **agent** (object) - Required - The agent the state belongs to. - **activityId** (string) - Required - The activity ID the state belongs to. - **stateId** (string) - Path Parameter - Required - The ID of the state document to create. - **registration** (string) - Optional - The registration ID to filter states by. #### Request Body - **state** (object) - Required - The state data to create or merge. - **etag** (string) - Optional - The ETag of the state to match for conditional requests. - **matchHeader** (string) - Optional - The type of match header to use ('If-Match' or 'If-None-Match'). ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json "State created successfully." ``` ## PUT /xapi/state/{stateId} ### Description Replaces an existing state document entirely. ### Method PUT ### Endpoint /xapi/state/{stateId} ### Parameters #### Query Parameters - **agent** (object) - Required - The agent the state belongs to. - **activityId** (string) - Required - The activity ID the state belongs to. - **stateId** (string) - Path Parameter - Required - The ID of the state document to replace. - **registration** (string) - Optional - The registration ID to filter states by. #### Request Body - **state** (object) - Required - The new state data. - **etag** (string) - Optional - The ETag of the state to match for conditional requests. - **matchHeader** (string) - Optional - The type of match header to use ('If-Match' or 'If-None-Match'). ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json "State updated successfully." ``` ## DELETE /xapi/state/{stateId} ### Description Deletes a specific state document. ### Method DELETE ### Endpoint /xapi/state/{stateId} ### Parameters #### Query Parameters - **agent** (object) - Required - The agent the state belongs to. - **activityId** (string) - Required - The activity ID the state belongs to. - **stateId** (string) - Path Parameter - Required - The ID of the state document to delete. - **registration** (string) - Optional - The registration ID to filter states by. - **etag** (string) - Optional - The ETag of the state to match for conditional requests. - **matchHeader** (string) - Optional - The type of match header to use ('If-Match' or 'If-None-Match'). ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json "State deleted successfully." ``` ``` -------------------------------- ### Activity Resource API Source: https://context7.com/xapijs/xapi-demo/llms.txt Endpoint for retrieving the definition of a specific activity from the LRS. ```APIDOC ## GET /xapi/activities ### Description Retrieves the complete definition of an activity from the LRS. ### Method GET ### Endpoint `/xapi/activities` ### Parameters #### Query Parameters - **activityId** (string) - Required - The ID of the activity to retrieve. ### Request Example ```json { "activityId": "https://www.xapijs.dev/activity/xapi-demo" } ``` ### Response #### Success Response (200 OK) - **data** (object) - The activity definition, including its ID and definition details. #### Response Example ```json { "id": "https://www.xapijs.dev/activity/xapi-demo", "definition": { "name": {"en": "xAPI Demo Activity"}, "description": {"en": "An example activity for xAPI demonstration."}, "type": "http://adlnet.gov/expapi/verbs/attempt" } } ``` ``` -------------------------------- ### Parse Launch Parameters from URL with TypeScript Source: https://context7.com/xapijs/xapi-demo/llms.txt Parses URL query parameters from the current location into an object. This is useful for extracting launch parameters provided by Learning Management Systems (LMS). ```typescript const params = XAPI.getSearchQueryParamsAsObject(location.href); // Returns: { endpoint: "https://...", auth: "Basic ...", actor: "{...}" } ``` -------------------------------- ### Statement Resource Source: https://context7.com/xapijs/xapi-demo/llms.txt Operations for retrieving, creating, and voiding statements in the LRS. ```APIDOC ## Statement Resource ### getStatement #### Description Retrieves a single statement by its ID with optional attachments and format parameters. #### Method `xapi.getStatement(options: { statementId: string, format?: string, attachments?: boolean }): Promise` #### Parameters ##### Query Parameters - **statementId** (string) - Required - The ID of the statement to retrieve. - **format** (string) - Optional - The format for retrieving the statement. Options: "exact", "ids", "canonical". - **attachments** (boolean) - Optional - Whether to include attachments in the response. Defaults to `false`. #### Response ##### Success Response (200) - **data** (object | array) - The retrieved statement object or an array of statements if attachments are requested and returned as part of an array. #### Request Example ```typescript // Basic statement retrieval xapi.getStatement({ statementId: "12345678-1234-1234-1234-123456789012", format: "exact" // Options: "exact", "ids", "canonical" }) .then((result) => { console.log("Statement:", result.data); }) .catch((error) => { console.error("Error:", error); }); // With attachments xapi.getStatement({ statementId: "12345678-1234-1234-1234-123456789012", attachments: true }) .then((result) => { console.log("Statement with attachments:", result.data[0]); }) .catch((error) => { console.error("Error:", error); }); ``` ### getVoidedStatement #### Description Retrieves a voided statement by its original statement ID. #### Method `xapi.getVoidedStatement(options: { voidedStatementId: string, format?: string, attachments?: boolean }): Promise` #### Parameters ##### Query Parameters - **voidedStatementId** (string) - Required - The ID of the original statement that was voided. - **format** (string) - Optional - The format for retrieving the voided statement. Options: "exact", "ids", "canonical". - **attachments** (boolean) - Optional - Whether to include attachments in the response. Defaults to `false`. #### Response ##### Success Response (200) - **data** (object) - The voided statement object. #### Request Example ```typescript xapi.getVoidedStatement({ voidedStatementId: "12345678-1234-1234-1234-123456789012", attachments: false, format: "exact" }) .then((result) => { console.log("Voided Statement:", result.data); }) .catch((error) => { console.error("Error:", error); }); ``` ``` -------------------------------- ### Agents Resource Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves and manages Agent objects within the LRS. ```APIDOC ## Agents Resource ### getAgent #### Description Retrieves a complete Agent object from the LRS based on the provided agent identifier. #### Method `xapi.getAgent(options: { agent: object }): Promise` #### Parameters ##### Request Body - **agent** (object) - Required - An object representing the agent to retrieve. Must include at least one identifier like `mbox` or `openid`. #### Response ##### Success Response (200) - **data** (object) - The retrieved Agent object. #### Response Example ```typescript xapi.getAgent({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" } }) .then((result) => { console.log("Agent:", result.data); // Returns: { objectType: "Agent", mbox: "mailto:learner@example.com", name: "John Doe" } }) .catch((error) => { console.error("Error:", error); }); ``` ``` -------------------------------- ### Statements API Source: https://context7.com/xapijs/xapi-demo/llms.txt Endpoints for retrieving and sending xAPI statements. ```APIDOC ## GET /xapi/statements ### Description Queries statements from the LRS with various filter parameters. ### Method GET ### Endpoint /xapi/statements ### Parameters #### Query Parameters - **agent** (object) - Optional - The agent to filter statements by. - **verb** (string) - Optional - The verb ID to filter statements by. - **activity** (string) - Optional - The activity ID to filter statements by. - **registration** (string) - Optional - The registration ID to filter statements by. - **related_activities** (boolean) - Optional - Whether to include statements related to the specified activity. - **related_agents** (boolean) - Optional - Whether to include statements related to the specified agent. - **since** (string) - Optional - Filter statements since a specific timestamp. - **until** (string) - Optional - Filter statements until a specific timestamp. - **limit** (integer) - Optional - The maximum number of statements to return. - **attachments** (boolean) - Optional - Whether to include attachments in the response. - **ascending** (boolean) - Optional - Whether to return statements in ascending order. - **format** (string) - Optional - The format of the response (e.g., 'exact'). ### Response #### Success Response (200) - **statements** (array) - An array of xAPI statements. - **more** (string) - A URL to retrieve more statements if available. #### Response Example ```json { "statements": [ { "id": "123e4567-e89b-12d3-a456-426614174000", "actor": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "verb": { "id": "http://adlnet.gov/expapi/verbs/experienced" }, "object": { "id": "https://www.xapijs.dev/activity/xapijs/xapi-demo" }, "timestamp": "2024-01-15T10:00:00Z" } ], "more": "/xapi/statements?cursor=abc123" } ``` ## POST /xapi/statements ### Description Sends a new xAPI statement to the LRS. ### Method POST ### Endpoint /xapi/statements ### Parameters #### Request Body - **statement** (object) - Required - The xAPI statement to send. ### Request Example ```json { "statement": { "actor": { "objectType": "Agent", "mbox": "mailto:learner@example.com", "name": "John Doe" }, "verb": { "id": "http://adlnet.gov/expapi/verbs/experienced", "display": {"en-US": "experienced"} }, "object": { "id": "https://www.xapijs.dev/activity/xapijs/xapi-demo", "definition": { "name": {"en-US": "xAPI.js Demo"}, "type": "http://adlnet.gov/expapi/activities/course" } } } } ``` ### Response #### Success Response (200) - **statementId** (string) - The ID of the created statement. #### Response Example ```json ["12345678-1234-1234-1234-123456789012"] ``` ## POST /xapi/statements/void ### Description Voids an existing statement by creating a voiding statement. ### Method POST ### Endpoint /xapi/statements/void ### Parameters #### Request Body - **actor** (object) - Required - The agent performing the voiding action. - **statementId** (string) - Required - The ID of the statement to void. ### Request Example ```json { "actor": { "objectType": "Agent", "mbox": "mailto:admin@example.com" }, "statementId": "12345678-1234-1234-1234-123456789012" } ``` ### Response #### Success Response (200) - **voidingStatementId** (string) - The ID of the voiding statement. #### Response Example ```json ["abcdef12-3456-7890-abcd-ef1234567890"] ``` ## GET /xapi/statements/more ### Description Retrieves additional statements using the "more" URL from a previous getStatements response. ### Method GET ### Endpoint /xapi/statements/more ### Parameters #### Query Parameters - **more** (string) - Required - The "more" URL provided in a previous response. ### Response #### Success Response (200) - **statements** (array) - An array of additional xAPI statements. - **more** (string) - A URL to retrieve further statements if available. #### Response Example ```json { "statements": [ { "id": "98765432-10fe-dcba-9876-543210fedcba", "actor": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "verb": { "id": "http://adlnet.gov/expapi/verbs/experienced" }, "object": { "id": "https://www.xapijs.dev/activity/xapijs/xapi-demo" }, "timestamp": "2024-01-16T11:00:00Z" } ], "more": "/xapi/statements?cursor=xyz789" } ``` ``` -------------------------------- ### Replace Agent Profile Document with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Replaces an existing agent profile document entirely with new data. Requires agent details, profile ID, the new profile data, and optionally an etag and matchHeader. ```typescript xapi.setAgentProfile({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" }, profileId: "preferences", profile: { language: "fr", theme: "light", notifications: false }, etag: '"xyz789"', matchHeader: "If-Match" }) .then((result) => { console.log("Profile updated:", result.data); }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Replace Activity Profile with xAPI.js Source: https://context7.com/xapijs/xapi-demo/llms.txt Replaces an existing activity profile document entirely with new data. This operation requires the activity ID, profile ID, the new profile data, and an ETag for conditional updates, typically using the 'If-Match' header. ```typescript xapi.setActivityProfile({ activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo", profileId: "course-structure", profile: { modules: ["intro", "chapter1", "chapter2", "quiz"], totalDuration: "PT3H" }, etag: '"def456"', matchHeader: "If-Match" }) .then((result) => { console.log("Activity profile updated:", result.data); }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Retrieve xAPI Launch Data Asynchronously with TypeScript Source: https://context7.com/xapijs/xapi-demo/llms.txt Asynchronously retrieves xAPI launch data according to the xAPI Launch specification. This method returns a Promise that resolves with the launch data or rejects with an error. ```typescript XAPI.getXAPILaunchData() .then((xAPILaunchData) => { console.log("Launch data:", xAPILaunchData); // Returns: { endpoint: "https://...", ... } }) .catch((error) => { console.error("Failed to get launch data:", error); }); ``` -------------------------------- ### State Management API Source: https://context7.com/xapijs/xapi-demo/llms.txt Endpoints for deleting individual state documents or all state documents for a given agent and activity. ```APIDOC ## DELETE /xapi/statements/state ### Description Deletes a specific state document associated with an agent and activity. ### Method DELETE ### Endpoint `/xapi/statements/state` ### Parameters #### Query Parameters - **agent** (object) - Required - The agent associated with the state. - **activityId** (string) - Required - The ID of the activity. - **stateId** (string) - Required - The ID of the state to delete. - **registration** (string) - Optional - The registration ID. - **etag** (string) - Optional - The ETag of the state to delete. ### Request Example ```json { "agent": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "activityId": "https://www.xapijs.dev/activity/xapijs/xapi-demo", "stateId": "bookmark", "registration": "ec531277-b57b-4c15-8d91-d292c5b2b8f7", "etag": "\"abc123\"" } ``` ### Response #### Success Response (204 No Content) - **No response body** #### Response Example (No content) ``` ```APIDOC ## DELETE /xapi/statements/state ### Description Deletes all state documents for a given agent and activity. ### Method DELETE ### Endpoint `/xapi/statements/state` ### Parameters #### Query Parameters - **agent** (object) - Required - The agent associated with the states. - **activityId** (string) - Required - The ID of the activity. - **registration** (string) - Optional - The registration ID. - **etag** (string) - Optional - The ETag of the states to delete. ### Request Example ```json { "agent": { "objectType": "Agent", "mbox": "mailto:learner@example.com" }, "activityId": "https://www.xapijs.dev/activity/xapijs/xapi-demo", "registration": "ec531277-b57b-4c15-8d91-d292c5b2b8f7", "etag": "\"abc123\"" } ``` ### Response #### Success Response (204 No Content) - **No response body** #### Response Example (No content) ``` -------------------------------- ### Retrieve More Statements (TypeScript) Source: https://context7.com/xapijs/xapi-demo/llms.txt Fetches additional sets of xAPI statements by providing the 'more' URL obtained from a previous `getStatements` call. This is essential for paginating through large numbers of statements. ```typescript xapi.getMoreStatements({ more: "/xapi/statements?cursor=abc123" }) .then((result) => { console.log("More Statements:", result.data); }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Create State Document (TypeScript) Source: https://context7.com/xapijs/xapi-demo/llms.txt Creates a new state document or merges with an existing one if the `etag` and `matchHeader` are provided correctly. This function is used to store and update state information for an agent and activity. ```typescript xapi.createState({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" }, activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo", stateId: "bookmark", state: { page: 10, section: "chapter3" }, registration: "ec531277-b57b-4c15-8d91-d292c5b2b8f7", etag: '"abc123"', matchHeader: "If-Match" // Options: "If-Match", "If-None-Match" }) .then((result) => { console.log("State created:", result.data); }) .catch((error) => { console.error("Error:", error); }); ``` -------------------------------- ### Retrieve Tin Can Launch Data with TypeScript Source: https://context7.com/xapijs/xapi-demo/llms.txt Retrieves TinCan launch parameters directly from the URL query string. This method is commonly used when content is launched from an LMS and automatically configures the xAPI client if endpoint and auth are found. ```typescript const tinCanLaunchData = XAPI.getTinCanLaunchData(); // Returns: { endpoint: "https://...", auth: "Basic ...", actor: { objectType: "Agent", ... } } if (tinCanLaunchData.endpoint) { const xapi = new XAPI({ endpoint: tinCanLaunchData.endpoint, auth: tinCanLaunchData.auth }); } ``` -------------------------------- ### Delete All State Documents for Agent and Activity with xAPI Source: https://context7.com/xapijs/xapi-demo/llms.txt Deletes all state documents associated with a given agent and activity. Requires agent details, activity ID, and optionally a registration and etag. ```typescript xapi.deleteStates({ agent: { objectType: "Agent", mbox: "mailto:learner@example.com" }, activityId: "https://www.xapijs.dev/activity/xapijs/xapi-demo", registration: "ec531277-b57b-4c15-8d91-d292c5b2b8f7", etag: '"abc123"' }) .then((result) => { console.log("All states deleted:", result.data); }) .catch((error) => { console.error("Error:", error); }); ```