### PHP Development Server Output Example Source: https://help.learnosity.com/hc/en-us/articles/360000757757-Environment-Setup-Guide-PHP This is an example of the output you would see when starting the PHP development server. It confirms the server has started, specifies the listening address and port, and indicates the document root directory. ```text lrn$ php -S localhost:8000 PHP 8.x Development Server started at $date, $time Listening on http://localhost:8000 Document root is ~/Public/www Press Ctrl-C to quit. ``` -------------------------------- ### Start PHP Development Server (macOS/Linux) Source: https://help.learnosity.com/hc/en-us/articles/360000757757-Environment-Setup-Guide-PHP This command starts a built-in PHP development server. It listens on localhost:8000 and uses the current directory as the web root. This is useful for local testing and development. ```bash php -S localhost:8000 ``` -------------------------------- ### PHP - Learnosity Grading API Quick Start Source: https://help.learnosity.com/hc/en-us/articles/25283285367453-Getting-started-with-the-Grading-API This snippet demonstrates the server-side setup for Learnosity's Grading API using PHP. It assumes a compatible consumer database and requires basic PHP, JavaScript, and HTML knowledge. The code is part of a quick start example package that includes the LearnositySDK. ```php "https://assess-api.learnosity.com", "request_type" => "POST", "action" => "save", "data" => [ // TODO: Populate with assessment data. ] ]; $sdk = new LearnositySdk($consumer_key, $consumer_secret); $response = $sdk->request($request); print_r($response); ?> ``` -------------------------------- ### PHP Learnosity SDK Example Source: https://help.learnosity.com/hc/en-us/article_attachments/360002648617 This snippet demonstrates the basic setup and usage of the Learnosity SDK in PHP. It includes initializing the SDK, setting up configuration, and making a sample API call. ```php "your_consumer_key", "consumer_secret" => "your_consumer_secret", "api_endpoint" => "https://api.learnosity.com" ); $learnosity = new LearnositySDK($config); $request_data = array( "user_id" => "user_123", "security" => array( "domain" => "localhost" ) ); try { $response = $learnosity->api("user/register", $request_data, "POST"); print_r($response); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ?> ``` -------------------------------- ### Install PHP on Ubuntu Linux Source: https://help.learnosity.com/hc/en-us/articles/360000757757-Environment-Setup-Guide-PHP This command installs PHP on Ubuntu Linux using the apt package manager. It requires superuser privileges (sudo) and will install the latest available version of PHP from the repositories. ```bash sudo apt install php ``` -------------------------------- ### Example Data API Request in Node.js Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCG2jt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCNGjt_b1e953_LVN0YXJ0ZWQtV2l0aC10aGUtRGF0YS1BUEkGOwhUOglyYW5raQY%3D--5d44fcaf15bdd1c74eccefd2500db44691742cc0 This Node.js example demonstrates how to construct and send a request to the Learnosity Data API using the Learnosity SDK. It assumes the SDK is installed and configured, and shows how to set up the security and request parameters. ```javascript const LearnositySDK = require('learnosity-sdk'); const security = { consumer_key: 'YOUR_CONSUMER_KEY', domain: 'YOUR_DOMAIN.com' }; const request = { "user_id": "student_0001", "mintime": "2011-01-01", "sort": "asc" }; LearnositySDK.init(security, 'YOUR_SECRET') .getResponses(request) .then(response => { console.log(response); }) .catch(error => { console.error(error); }); ``` -------------------------------- ### PHP Standalone Assessment Example Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCCqXt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCMWgt_7cd354_5nLVN0YXJ0ZWQtd2l0aC10aGUtSXRlbXMtQVBJBjsIVDoJcmFua2kJ--d9be7fa8e9cf51571eb8118250f1aff67fbe256b This snippet demonstrates how to construct and securely sign configuration options for the Learnosity Items API using PHP. It is intended for server-side execution to prepare assessment data before it's rendered client-side. Prerequisites include basic PHP knowledge and a PHP-enabled web server. ```php "user_id", "domain" => "localhost", // A unique ID for the session "session_id" => uniqid(), "items" => array( // Use either an `id` or `reference` to load an item // "id" => "5c2c2f237d724742b0b12614" // Or "reference" => "standalone-assessment-example-1" ) ); $security = array( "consumer_key" => $consumer_key, // Request timestamp "timestamp" => gmdate("YmdHis"), // Request signature "signature" => $lrn->generate_signature($consumer_secret, 'request', $request) ); $request_data = [ "request" => $request, "security" => $security ]; // This will be used to initialize the Learnosity player client-side $json_request = json_encode($request_data); ?> Standalone Assessment
``` -------------------------------- ### PHP SDK Setup for Learnosity API Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCIKUt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCOKTt_b4eb14_luZy1EaXN0cmFjdG9yLVJhdGlvbmFsZQY7CFQ6CXJhbmtpBg%3D%3D--7e7535c0e72d1c9b942095e7432807e3e89050f8 Example of setting up the Learnosity SDK in PHP for secure API requests. Includes configuration for consumer key, secret, and allowlisted domains, utilizing the autoloader for dependency management. ```php // Assuming a config file exists with your credentials require 'path/to/your/Learnosity/autoload.php'; use LearnositySdk\Process\LearnositySdk; $config = require 'path/to/your/config.php'; // Contains consumer_key, consumer_secret, domain $api_init = [ "consumer_key" => $config['consumer_key'], "consumer_secret" => $config['consumer_secret'], "domain" => $config['domain'] ]; $sdk = new LearnositySdk($api_init); // Example assessment request data $requestData = [ // ... your assessment request data ... ]; // Sign the request $signedRequest = $sdk->sign("assess", $requestData); // or "items", "reports", etc. echo json_encode($signedRequest); ``` -------------------------------- ### Standalone Assessment Example (PHP) Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCCqXt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCO6Wt_42c838_5nLVN0YXJ0ZWQtd2l0aC10aGUtSXRlbXMtQVBJBjsIVDoJcmFua2kJ--f68f6302cb44a7e6a10df666bce0e7d9c0644845 This PHP code constructs configuration options for the Learnosity Items API and securely signs them using a consumer key. It is the server-side component for embedding an assessment. ```php \"YOUR_CONSUMER_KEY\", \"consumer_secret\" => \"YOUR_CONSUMER_SECRET\", \"service_type\" => \"items\" ); $lr = new Learnosity($config); $request = array( \"user\" => array( \"id\" => \"user-123\" ), \"session_id\" => \"session-123\", \"domain\" => \"localhost\" ); $signed_request = $lr->sign($request); ?>
``` -------------------------------- ### Create Hello World PHP File (macOS/Linux) Source: https://help.learnosity.com/hc/en-us/articles/360000757757-Environment-Setup-Guide-PHP This snippet demonstrates how to create a basic 'Hello World' PHP file. The code includes simple HTML structure and uses PHP's echo function to display a paragraph. This file should be saved in the web root directory. ```php PHP Test Hello World

'; ?> ``` -------------------------------- ### API Initialization Request JSON Example Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCMGft9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCCKVt_eec852_Y5Ny1SYWlzaW5nLWEtU3VwcG9ydC1SZXF1ZXN0BjsIVDoJcmFua2kI--0f8d2cdd662882c428f318a0446bbd5caa519292 An example of the JSON initialization request that should be provided when reporting an issue with Learnosity APIs. This helps the support team understand the exact parameters being used. ```json { "consumer_key": "YOUR_CONSUMER_KEY", "request": { "user": { "id": "user-1234" }, "items": [ { "id": "unique-item-id-1", "type": "multiple-choice", "question": "What is the capital of France?", "options": [ "Berlin", "Madrid", "Paris", "Rome" ], "valid_response": 2 } ] } } ``` -------------------------------- ### Local Development Server Command Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCBEhjMwDBDoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCD2ht_e9f6ee_dG9tLVF1ZXN0aW9ucy1hbmQtRmVhdHVyZXMGOwhUOglyYW5raQk%3D--d72d692d33d538b3d05a1b20087dcc300a1e37c5 Command to start a local development server, typically used with the Custom Question Skeleton project. This allows for live testing of custom questions at a specified localhost URL. ```bash # Command to start the development server yarn dev ``` -------------------------------- ### PHP Example for Learnosity Reports Source: https://help.learnosity.com/hc/en-us/article_attachments/360002648617 This snippet demonstrates how to configure and retrieve reports using the Learnosity SDK in PHP. It requires the SDK to be installed and configured with appropriate API credentials. ```php setConsumerKey($consumerKey); $init->setConsumerSecret($consumerSecret); // Example for Reports API $reportType = 'session_activity'; // e.g., session_activity, item_ids, etc. $request = new PostRequest($init, 'reports', array(), array('report_type' => $reportType)); $response = $request->execute(); print_r($response); ?> ``` -------------------------------- ### Initialize Learnosity SDK Source: https://help.learnosity.com/hc/en-us/articles/16458107874973-LearnosityApp-Questions-API Initializes the Learnosity SDK, typically done once at the start of your application. This setup is crucial for all subsequent SDK operations. ```javascript LearnosityApp.init(); ``` -------------------------------- ### PHP Server-Side Configuration for Learnosity Items API Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCCqXt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCGU%2_a106a5_5nLVN0YXJ0ZWQtd2l0aC10aGUtSXRlbXMtQVBJBjsIVDoJcmFua2kH--0c93ba49dc20d3bfd50ad4cae440757dde67b506 This PHP code constructs configuration options for the Learnosity Items API and securely signs them using a consumer key. It's executed server-side to prepare the assessment for the client. ```php "0123456789abcdef", "consumer_secret" => "abcdef0123456789abcdef0123456789abcdef0123456789" ); // Instantiate the SDK with your configuration $LearnositySDK = new LearnositySDK($config); // Define the session and activity details $session_id = "session-id-example"; $user_id = "user-id-example"; // Define the items API request $itemsAPIRequest = array( "assessmentItemTypes" => "multiple_choice,ordered_list", "references" => array( "my_first_assessment" ) ); // Generate the Learnosity API request, including the signed request and session/user details $signedRequest = $LearnositySDK->generate( "items", array( "session_id" => $session_id, "user_id" => $user_id ), $itemsAPIRequest ); ?> ``` -------------------------------- ### PHP Tutorial: Basic Example Source: https://help.learnosity.com/hc/en-us/article_attachments/360002648617 A fundamental PHP tutorial file. This code snippet serves as a basic example for learning or demonstrating PHP functionalities. It might contain simple variable assignments, control structures, or function definitions, providing a starting point for PHP development. ```php ``` -------------------------------- ### Start Static Web Server (JavaScript) Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCKp%2FwdJTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCPG_284848_Fybm9zaXR5LUFzc2Vzc21lbnQtQVBJcwY7CFQ6CXJhbmtpBw%3D%3D--4ae68f2b18495f6109b05179e182cd140dddf2ac Starts a static web server using `react-native-static-server` to serve content from the 'www' folder. It handles server initialization, URL retrieval, and ensures previous server instances are stopped before starting a new one. ```javascript import StaticServer from 'react-native-static-server'; import RNFS from 'react-native-fs'; let path = RNFS.MainBundlePath + '/www'; let server = new StaticServer(12345, path); let serverUrl = null; export function startServer() { if (!server) { return Promise.reject('WebServerManager is undefined'); } stopServer(); return server.start() .then((url) => { serverUrl = url; console.log('Web Server started'); }) .catch(err => console.error(err)); } ``` -------------------------------- ### Install PHP on macOS using Homebrew Source: https://help.learnosity.com/hc/en-us/articles/360000757757-Environment-Setup-Guide-PHP This command installs PHP on macOS using the Homebrew package manager. It's a common method for managing software on macOS if PHP is not pre-installed or requires an update. ```bash brew install php ``` -------------------------------- ### PHP Server-Side Configuration for Learnosity Items API Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCCqXt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCL2jt_c485ba_5nLVN0YXJ0ZWQtd2l0aC10aGUtSXRlbXMtQVBJBjsIVDoJcmFua2kG--ccdafda65b176538c5f00e51ce7186d13b914385 This PHP code constructs configuration options for the Learnosity Items API and securely signs them using a consumer key. It's the server-side component responsible for initializing the assessment. ```php $consumer_key, // "domain" => $domain, // // ... other initialization options ... // ]; // $request = LearnositySDK::init($init_options); // $signed_init_options = $request->generate_signed_request("GET", "items", null, $consumer_secret); // For demonstration purposes, we'll simulate the output structure: $signed_init_options = [ "status" => "success", "data" => [ "items" => [ [ "id" => "sample-item-1", "reference" => "sample-item-ref-1", "status" => "published", "type" => "activity", "name" => "Sample Activity", "description" => "A sample assessment activity.", "questions" => [ [ "id" => "sample-question-1", "reference" => "sample-question-ref-1", "type" => "multiple_choice", "question" => "What is the capital of France?", "options" => [ "A" => "London", "B" => "Paris", "C" => "Berlin", "D" => "Madrid" ], "answer" => "B" ] ] ] ], "api_url" => "https://items.learnosity.com/v1/init", "token" => "sample-token-12345" ] ]; ?> ``` -------------------------------- ### PHP Server-Side Configuration for Learnosity Items API Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCCqXt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCImgt_8e067f_5nLVN0YXJ0ZWQtd2l0aC10aGUtSXRlbXMtQVBJBjsIVDoJcmFua2kH--45e50732ee0801ae6dae74f94cc2970f43905083 This server-side PHP code constructs configuration options for the Learnosity Items API and securely signs them using a consumer key. It is a prerequisite for initializing the assessment client-side. ```php 'YOUR_CONSUMER_KEY', 'domain' => 'learnosity.com', 'api_version' => 'v1', 'service' => 'items' ]; // Initialize Learnosity SDK $itemsApp = LearnositySdk\LearnositySdk::createItemsApp( $config ); // Prepare session options (example) $sessionOptions = [ 'user_id' => 'user_123', 'items' => [ 'item_ids' => ['your_item_id_1', 'your_item_id_2'] ] ]; // Generate the signed request for the Items API $signedRequest = $itemsApp->init( $sessionOptions ); ?> ``` -------------------------------- ### Learnosity Reports API - Getting Started Source: https://help.learnosity.com/hc/en-us/articles/360000755838-Getting-Started-With-the-Reports-API Guide to embedding reports into your application using Learnosity's Reports API. ```APIDOC ## Learnosity Reports API - Getting Started ### Overview This guide describes the simplest way to embed a report into your application using Learnosity's Reports API. It covers setting up a simple example page to present a student's assessment results and details the code involved. - **Time to complete**: 10 minutes. ### Prerequisites - Basic PHP, JavaScript, and HTML knowledge. - A PHP-enabled web server installed on your local machine. (Refer to the environment setup FAQ for setup instructions). - Server-side code examples are provided in PHP, with support for other languages like Java, .NET, and Python. ### Download Quick Start Examples 1. Download the Learnosity quick start examples zip file. 2. Unzip the files and configure your web server to use `quickstart-examples-php/www` as its document root. 3. Assume your web server is available at `localhost:8000`. ### View the Student Reporting Example - Access the student reporting example at `http://localhost:8000/analytics/student-reporting.php`. - Alternatively, select 'student reporting' from the index page (`http://localhost:8000/index.html`). ### How it Works The analytics example code (`www/analytics/student-reporting.php`) is divided into two main sections: 1. **Server-side (PHP)**: Constructs configuration options for the Reports API and securely signs them using the consumer key. 2. **Client-side (HTML and JavaScript)**: Renders and executes the reporting functionality once the page loads in the browser. ``` -------------------------------- ### Embed Standalone Assessment using PHP and JavaScript Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCCqXt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCILQB_29eba4_5nLVN0YXJ0ZWQtd2l0aC10aGUtSXRlbXMtQVBJBjsIVDoJcmFua2kJ--230eda94bfc5b5d32646f08b6209f81d3a6b6c6e This snippet demonstrates embedding a standalone assessment using Learnosity's Items API. It includes server-side PHP code for constructing and signing configuration options, and client-side HTML and JavaScript for rendering and running the assessment. This example requires the Learnosity SDK and assumes a local web server setup. ```php "YOUR_CONSUMER_KEY", "consumer_secret" => "YOUR_CONSUMER_SECRET" ); // Learnosity API configuration $learnositySdk = new Learnosity($config); $itemsConfig = array( "domain" => "http://localhost:8000", "items" => [ [ "id" => "standalone-assessment-example", "reference" => "quickstart-standalone" ] ], "user" => [ "id" => "quickstart-user-1" ], "assess_api" => [ "enable_questions_api" => true, "return_all_assessments" => true ] ); // Generate signed request $signedRequest = $learnositySdk->generate(array_merge($itemsConfig, [ "timestamp" => gmdate('Ymdhis') . '000', "nonce" => "2_NONCE_HERE", "signature" => "SIGNATURE_HERE", "content" => "CONTENT_HERE" ])); ?> Standalone Assessment Example
``` -------------------------------- ### POST /createUI Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCJ35J0ITEzoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCB0hE_8fae6c_NrLUFpZGUtQVBJLVJlbGVhc2UtTG9ncwY7CFQ6CXJhbmtpBg%3D%3D--a8c8221426a41d0d233913d4b7b8fb0f0d633864 Allows for the creation of a UI with various configuration options, including math rendering and rubric layout. ```APIDOC ## POST /createUI ### Description Allows for the creation of a UI with various configuration options, including math rendering and rubric layout. ### Method POST ### Endpoint /createUI ### Parameters #### Request Body - **enable_math_rendering** (boolean) - Optional - If true, enables LaTeX rendering in the UI. - **rubric_layout** (string) - Optional - Specifies the rubric layout. Allowed values: `auto`, `compact`, `full`. - **options** (object) - Optional - Additional options for fine-grained control over the UI. ### Request Example ```json { "enable_math_rendering": true, "rubric_layout": "compact", "options": { "some_option": "value" } } ``` ### Response #### Success Response (200) - **ui_id** (string) - The unique identifier for the created UI. #### Response Example ```json { "ui_id": "ui_12345" } ``` ``` -------------------------------- ### Get Jobs Request Body Example (JSON) Source: https://help.learnosity.com/hc/en-us/articles/26076318439197-Jobs-Endpoints-Data-API Provides an example of a JSON request body for the 'get' action of the Jobs endpoint. This example shows how to specify job references for retrieval. ```json { "references": [ "9fd443d0-2b4f-4315-aec6-708da3d30d49" ] } ``` -------------------------------- ### PHP: Initialize Learnosity SDK and Author Aide API Config Source: https://help.learnosity.com/hc/en-us/articles/19751636225181-Getting-started-with-the-Author-Aide-API Includes the Learnosity SDK, declares configuration options for the Author Aide API including user and organization details, and sets up consumer credentials and security settings for request authorization. ```php [ 'id' => 123, 'firstname' => 'firstname', 'lastname' => 'lastname', 'email' => 'firstname.lastname@email.com' ], 'organisation_id' => 999 ]; $consumerKey = 'YOUR_CONSUMER_KEY'; $consumerSecret = 'YOUR_CONSUMER_SECRET'; $security = [ 'domain' => $_SERVER['SERVER_NAME'], 'consumer_key' => $consumerKey ]; $Init = new Init('authoraide', $security, $consumer_secret, $request); $signedRequest = $Init->generate(); ?> ``` -------------------------------- ### Initialize Learnosity SDK with Authentication (PHP) Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCIKUt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCB25u_5bf123_luZy1EaXN0cmFjdG9yLVJhdGlvbmFsZQY7CFQ6CXJhbmtpCg%3D%3D--d95d3152dc42cc0bdd3128923fe1099ec1f32970 Shows a basic PHP example of how to initialize the Learnosity SDK, including placeholder values for customer key and secret, and an allowlisted domain. This setup is crucial for secure API interactions and is used in conjunction with assessment request data. ```php $config = array( "consumer_key" => "YOUR_CONSUMER_KEY", "consumer_secret" => "YOUR_CONSUMER_SECRET", "domain" => "YOUR_ALLOWED_DOMAIN" ); // Include SDK autoloader require_once("path/to/learnosity/autoload.php"); // Initialize SDK $LearnositySDK = new $_LEARNOSITYSDK($config); ``` -------------------------------- ### Get Item Pools Request Body Example (JSON) Source: https://help.learnosity.com/hc/en-us/articles/26076363663005-Pools-Endpoints-Data-API Provides an example of a JSON request body for the 'Get Pools' endpoint of the Learnosity Data API. This specifies the 'references' parameter to retrieve specific Item pools. ```JSON { "references": ["ela-district-a"] } ``` -------------------------------- ### HTML Index Page Source: https://help.learnosity.com/hc/en-us/article_attachments/360002648617 This is a basic HTML file, index.html, serving as the entry point or index for the tutorial samples. It likely contains links to other tutorials or introductory content. Its primary function is to structure the presentation of the learning materials. ```html Tutorial Samples

Welcome to the Learnosity Tutorial Samples

Explore the different tutorials available.

``` -------------------------------- ### Get Tags Request Body Example Source: https://help.learnosity.com/hc/en-us/articles/26076379042589-Tags-Endpoints-Data-API Provides an example of a JSON request body for the 'Get Tags' endpoint. This shows the necessary parameters like 'organisation_id' and optional filters such as 'limit', 'names', 'sort', and 'types'. ```json { "action": "get", "organisation_id": 1, "limit": 50, "names": ["tag1", "tag2"], "sort": "asc", "sort_field": "updated", "types": ["type1", "type2"] } ``` -------------------------------- ### Get Tag Hierarchies Request Body Example Source: https://help.learnosity.com/hc/en-us/articles/26076373806749-Tag-hierarchies-Endpoints-Data-API An example of the JSON request body to be sent via POST to the Get Tag Hierarchies endpoint. It includes the organization ID and a list of hierarchy references. ```json { "references": ["TagHierarchyTest"] } ``` -------------------------------- ### Initialize Learnosity SDK with Authentication (PHP) Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCIKUt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCJ0pd_efcd3b_luZy1EaXN0cmFjdG9yLVJhdGlvbmFsZQY7CFQ6CXJhbmtpCQ%3D%3D--87cb5fa6170f26cfa4592e145d52eaad646f680e Illustrates how to initialize the Learnosity SDK in PHP, including setting up security and authentication. This involves using a configuration file that contains customer keys, secrets, and allowlisted domains. The SDK autoloader simplifies dependency management. ```php // Assuming config.php contains your credentials and SDK autoloader require_once 'config.php'; use LearnositySdk\Process\LearnositySdk; // Assessment request data $request = [ // ... your assessment data ... ]; // Initialize Learnosity SDK $sdk = new LearnositySdk(LEARNOSITY_CONSUMER_KEY, LEARNOSITY_CONSUMER_SECRET, LEARNOSITY_DOMAIN); // Sign the request using SHA256 $signedRequest = $sdk->sign($request); // You would then send $signedRequest to Learnosity servers. ``` -------------------------------- ### Standalone Assessment Example (PHP) Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCCqXt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCP2ft_66dc9e_5nLVN0YXJ0ZWQtd2l0aC10aGUtSXRlbXMtQVBJBjsIVDoJcmFua2kI--a1c5b376211ea8ef644cc8b9c825c96ca467ead3 This PHP code constructs configuration options for the Learnosity Items API and securely signs them using a consumer key. It's designed to be executed server-side and prepares data for the client-side assessment rendering. ```PHP "localhost", "request" => array( "item_reference" => "your_item_reference", "activity_template_id" => "your_activity_template_id", "user_id" => "user_123" ) ); $signedRequest = $lrn->generate($request); ?> Standalone Assessment
``` -------------------------------- ### API Initialization Example Source: https://help.learnosity.com/hc/en-us/articles/16760630504989-fontsize-Initialization-Questions-API Illustrates a basic structure for initializing the Learnosity API. This typically involves setting up configuration options before proceeding with feature integrations. No specific external dependencies are highlighted, but it forms the foundational step for utilizing Learnosity's services. ```javascript // Example of API Initialization Learnosity.init(config, callback); ``` -------------------------------- ### Get Workflows Request Body Example (JSON) Source: https://help.learnosity.com/hc/en-us/articles/26076399599005-Workflows-Endpoints-Data-API Provides an example of the JSON request body for the 'Get Workflows' endpoint. This includes specifying the 'organisation_id' and optionally 'limit', 'next', and 'references' for targeted retrieval of workflow data. ```json { "request": { "references": [ "Default workflow" ] } } ``` -------------------------------- ### Initialize Learnosity SDK with PHP for Items API Source: https://help.learnosity.com/hc/en-us/articles/360000755498-Getting-Started-with-the-Items-API This snippet demonstrates the server-side initialization of Learnosity SDK for the Items API using PHP. It includes setting up consumer credentials, defining request parameters, generating unique user and session IDs, and securely signing the configuration using the `Init` helper. The output is a JSON blob of signed configuration parameters ready to be passed to the client-side. ```php $user_id, 'activity_template_id' => 'quickstart_examples_activity_template_001', 'session_id' => $session_id, 'activity_id' => 'quickstart_examples_activity_001', 'rendering_type' => 'assess', 'type' => 'submit_practice', 'name' => 'Items API Quickstart', ]; $consumerKey = 'yis0TYCu7U9V4o7M'; $consumerSecret = '74c5fd430cf1242a527f6223aebd42d30464be22'; $security = [ 'domain' => $_SERVER['SERVER_NAME'], 'consumer_key' => $consumerKey ]; $init = new Init( 'items', $security, $consumerSecret, $request ); $initOptions = $init->generate(); ?> ``` -------------------------------- ### Initialize Learnosity Events API (JavaScript) Source: https://help.learnosity.com/hc/en-us/articles/16458061832605-initialization-Events-API Example demonstrating how to initialize the Learnosity Events API with security credentials, user mappings, and callback functions. This code sets up the necessary options and calls the `init` method to start the API. It includes placeholders for sensitive information like consumer keys and signatures. ```javascript var initializationOptions = { "security": { "consumer_key": "INSERT_CONSUMER_KEY_HERE", "domain": "my.domain.com", "timestamp": "20250408-1234", "signature": "SHA256-HASH - See Security", "user_id": "INSERT_USER_ID" }, "config": { "users": { "learner001": "7224f1cd26c7eaac4f30c16ccf8e143005734089724affe0dd9cbf008b941e2d", "learner002": "1e94cba9c43295121a8c93c476601f4f54ce1ee93ddc7f6fb681729c90979b7f", "learner003": "ca2d79d6e1c6c926f2b49f3d6052c060bed6b45e42786ff6c5293b9f3c723bdf", "learner004": "fd1888ffc8cf87efb4ab620401130c76fc8dff5ca04f139e23a7437c56f8f310" }, "ignore_past_events": false, } }; var callbacks = { readyListener: function () { console.log("Learnosity Events API is ready"); }, errorListener: function (e) { console.log('error', e); } }; var eventsApp = window.LearnosityEvents.init(initializationOptions, callbacks); ``` -------------------------------- ### PHP: Include Learnosity SDK and Initialize Author Aide Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCJ3MQsn2EToYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCJ0xc_4bae77_ZC13aXRoLXRoZS1BdXRob3ItQWlkZS1BUEkGOwhUOglyYW5raQc%3D--c4ec56d20f56ea39384ed855ccc6ab8835ddfe1b This snippet demonstrates how to include the Learnosity SDK, declare configuration options for the Author Aide API, and construct the request object with user and organization details. It requires basic PHP knowledge and the Learnosity SDK to be installed. ```php [ 'id' => 123, 'firstname' => 'firstname', 'lastname' => 'lastname', 'email' => 'firstname.lastname@email.com' ], 'organisation_id' => 999 ]; ?> ``` -------------------------------- ### Data API POST /data Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCG2jt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCJ3MA_26b37b_LVN0YXJ0ZWQtV2l0aC10aGUtRGF0YS1BUEkGOwhUOglyYW5raQo%3D--9cbf6ef34e0c1254b61ddce9e4b3c41c283253bf This example demonstrates setting data using the Data API. It includes setting up security, defining the data request, and making the API call. ```APIDOC ## POST /data ### Description This endpoint is used to set or update data within the Learnosity system. It requires proper security credentials and a structured data request. ### Method POST ### Endpoint /data ### Parameters #### Request Body - **itembank_uri** (string) - Required - The URI of the item bank to target. - **security_packet** (object) - Required - Contains security credentials. - **consumer_key** (string) - Required - Your API consumer key. - **domain** (string) - Required - The domain from which the request is made. - **consumer_secret** (string) - Required - Your API consumer secret. - **data_request** (object) - Required - The data payload to be set. - **items** (array) - Optional - An array of items to be set. - **id** (string) - Required - The unique identifier for the item. - **type** (string) - Required - The type of the item (e.g., 'mcq'). - **value** (string) - Required - The content of the item. - **label** (string) - Optional - A descriptive label for the item. - **stimulus** (string) - Optional - The question stem for the item. - **options** (array) - Optional - An array of response options for multiple-choice questions. - **value** (string) - Required - The value of the option. - **label** (string) - Required - The text displayed for the option. - **validation** (object) - Optional - Validation rules for the item. - **scoring_type** (string) - Required - The type of scoring (e.g., 'exactMatch'). - **valid_response** (array) - Required - Defines the correct answer(s). - **value** (array) - Required - An array containing the value(s) of the correct response. - **score** (number) - Required - The score awarded for the correct response. ### Request Example ```json { "itembank_uri": "your_itembank_uri", "security_packet": { "consumer_key": "your_consumer_key", "domain": "your_domain" }, "consumer_secret": "your_consumer_secret", "data_request": { "items": [ { "id": "unique-item-id-123", "type": "mcq", "value": "What is the capital of France?", "options": [ { "value": "A", "label": "London" }, { "value": "B", "label": "Paris" }, { "value": "C", "label": "Berlin" } ], "validation": { "scoring_type": "exactMatch", "valid_response": [ { "value": ["B"], "score": 1 } ] } } ] } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A message describing the result of the operation. #### Response Example ```json { "status": "ok", "message": "Data set successfully." } ``` ``` -------------------------------- ### Data API Request Body for Get Activity Player Templates Source: https://help.learnosity.com/hc/en-us/articles/26076390673565-Activity-player-templates-Endpoints-Data-API Provides an example of the request body for the 'get Activity Player Templates' endpoint. Note that for this specific endpoint, no parameters are required in the body. ```json {} ``` -------------------------------- ### Hard Timer Example: Early Start Attempt Source: https://help.learnosity.com/hc/en-us/articles/14356818230813 Illustrates how a student attempting to start an assessment before its scheduled 'start_time' will encounter a countdown. Once the assessment begins, the 'max_time' countdown commences. ```javascript { "assessment": { "start_time": "2023-10-27T14:00:00Z", "max_time": 1800 // 30 minutes in seconds } } ``` -------------------------------- ### Start Static Web Server (React Native) Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCKp%2FwdJTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCMI_a153d4_Fybm9zaXR5LUFzc2Vzc21lbnQtQVBJcwY7CFQ6CXJhbmtpCQ%3D%3D--313f5692141174baef0a67e94695db4f99b5e64b Starts a static web server using 'react-native-static-server' to serve content from the 'www' folder. It defines the path to the content and the port the server will run on. This is useful for serving Learnosity activities locally. Dependencies include 'react-native-static-server' and 'react-native-fs'. ```javascript import StaticServer from 'react-native-static-server'; import RNFS from 'react-native-fs'; // path where files will be served from (index.html here) let path = RNFS.MainBundlePath + '/www'; let server = new StaticServer(12345, path); let serverUrl = null; export function startServer() { if (!server) { return Promise.reject('WebServerManager is undefined'); } stopServer(); return server.start() .then((url) => { serverUrl = url; console.log('Web Server started'); }) .catch(err => console.error(err)); } export function stopServer() { if (!server) { return; } server.stop(); } export function isServerRunning() { if (!server) { return Promise.reject(false); } return server.isRunning(); } export function getUrl() { return serverUrl ? 'http://localhost:12345' : null; } ``` -------------------------------- ### Questions API Initialization Example Source: https://help.learnosity.com/hc/en-us/categories/16534061467933-Questions-API-Initialization-Options Example demonstrating the initialization of the Learnosity Questions API. It shows the mandatory Initialization object and the optional Callbacks object passed to the `window.LearnosityApp.init()` method. This is the primary entry point for using the Questions API. ```javascript window.LearnosityApp.init({ // Initialization object properties go here // e.g., apiKey: "your-api-key", // assessmentId: "your-assessment-id" }, { // Callbacks object properties go here (optional) // e.g., onError: function(error) { console.error(error); }, // onReady: function() { console.log("Questions API is ready!"); } }); ``` -------------------------------- ### LearnosityApp Initialization and Methods Source: https://help.learnosity.com/hc/en-us/articles/16458107874973-learnosityApp-Questions-API This snippet outlines the basic methods available for initializing and interacting with the LearnosityApp. It covers essential functions for setup and feature management. No external dependencies are explicitly mentioned for these core methods. ```javascript LearnosityApp.init(); LearnosityApp.push(); LearnosityApp.offline(); LearnosityApp.renderMath(); LearnosityApp.simpleFeature(); LearnosityApp.simpleFeatures(); ``` -------------------------------- ### Data API - Deprecation of Get Activity Base Templates Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCB0dkmkJBToYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCJEAE_a3d19b_lncmF0aW9uLUd1aWRlLWZvci0yMDIyLTItTFRTBjsIVDoJcmFua2kH--30c762e4e8ea079393af00fe019017139f4a1540 The Get Activity Base Templates endpoint in the Data API has been deprecated. It is recommended to use the Get Activity Custom Templates endpoint instead. ```APIDOC ## Data API ### Description Base Templates have been deprecated. Calling the `Get Activity Base Templates` endpoint in Data API will return a deprecation warning. Users should use the `Get Activity Custom Templates` endpoint in Data API to fetch custom player templates created using Author API. ### Method GET ### Endpoint `/data-api/activity/templates/base` (Deprecated) `/data-api/activity/templates/custom` (Recommended) ### Parameters None ### Request Example (Not applicable for deprecated endpoint. Refer to `Get Activity Custom Templates` for current usage.) ### Response #### Success Response (200) - **message** (string) - Deprecation warning for the base templates endpoint. - **data** (array) - List of custom activity templates for the recommended endpoint. #### Response Example (Deprecated Endpoint Example) ```json { "message": "This endpoint is deprecated. Please use Get Activity Custom Templates.", "data": [] } ``` (Recommended Endpoint Example) ```json { "data": [ { "templateId": "custom_template_1", "name": "My Custom Template" } ] } ``` ``` -------------------------------- ### GET /sessions/responses Source: https://help.learnosity.com/hc/en-us/related/click_data=BAh7CjobZGVzdGluYXRpb25fYXJ0aWNsZV9pZGwrCG2jt9FTADoYcmVmZXJyZXJfYXJ0aWNsZV9pZGwrCEKTt_35c61a_LVN0YXJ0ZWQtV2l0aC10aGUtRGF0YS1BUEkGOwhUOglyYW5raQo%3D--258802c4a149ad849eff24d4a289f33a6864c9cc Retrieves session information for a specified student, including their responses to assessment questions. This example demonstrates a 'get' operation. ```APIDOC ## POST /sessions/responses ### Description Retrieves session information for a specified student, including their responses to assessment questions. This example demonstrates a 'get' operation. ### Method POST ### Endpoint `https://data.learnosity.com/v2023.1.LTS/sessions/responses` ### Parameters #### Query Parameters - **user_id** (array) - Required - The ID(s) of the user(s) to retrieve data for. - **mintime** (string) - Optional - The minimum timestamp for the data retrieval (YYYY-MM-DD). - **maxtime** (string) - Optional - The maximum timestamp for the data retrieval (YYYY-MM-DD). - **limit** (integer) - Optional - The maximum number of results to return. #### Request Body This endpoint uses a POST request with a JSON payload for the request options. ```json { "user_id": ["student_0001"], "mintime": "2020-01-01", "maxtime": "2020-12-31", "limit": 1 } ``` ### Request Example ```php $consumerKey, 'domain' => 'localhost' ]; $consumer_secret = $config['consumerSecret']; $data_api = new DataApi(); $data_request = [ 'user_id' => ['student_0001'], 'mintime' => '2020-01-01', 'maxtime' => '2020-12-31', 'limit' => 1 ]; $result = $data_api->request( $itembank_uri, $security_packet, $consumer_secret, $data_request, 'get' ); echo "<<< [" . $result->getStatusCode() . "]" . PHP_EOL; print_r($result->getBody()); ?> ``` ### Response #### Success Response (200) - **body** (string) - The JSON string containing the session and response data. #### Response Example ```json { "responses": [ { "session_id": "...", "user_id": "student_0001", "responses": { "question_reference_1": { "response": "...", "score": "...", "..." } } } ] } ``` ```