Getting started with the Author Aide API

Overview

This guide describes the basics of embedding, configuring and working with Learnosity's Author Aide API, an AI powered Item generator and translator to supercharge productivity for your Authors.

We'll set up a simple example page for creating learning content using Author Aide API, then look at the code in detail.

Prerequisites

  • Basic PHP, JavaScript and HTML knowledge.
  • This quick start's server side code is written in PHP, but multiple languages are supported, such as Java, .net, Python and more.
  • A PHP-enabled web server, installed on your local machine. (To set up a simple test environment, follow our environment setup guide.)

Download the quickstart example, or visit our PHP GitHub repository for other options such as "git clone", or installation via Composer.

The quick start example package includes:

  • The Learnosity Software Development Kit (LearnositySDK).
  • The quick start example files.

Once set up, you can load the examples index page at http://localhost:8000/index.html.

How it works

Server-side code

We start by including some Learnosity SDK helpers - they'll make it easy to generate and sign the config options.

<?php
    include_once 'vendor/autoload.php';
    use LearnositySdk\Request\Init;

Then we declare the config options for Author Aide API:

  • user user information
  • organisation_id organisation ID, when not given, the default organisation of the used consumer will be used.
$request = [
    'user' => [
        'id' => 123,
        'firstname' => 'firstname',
        'lastname' => 'lastname',
        'email' => 'firstname.lastname@email.com'
    ],
   'organisation_id' => 999
];

Next, we declare the Learnosity consumer credentials we'll use to authorise this request. These keys grant access to Learnosity's public demos account. Once Learnosity provides you with your own consumer credentials, your Item bank and assessment data will be tied to your consumer key.

$consumerKey = 'yis0TYCu7U9V4o7M';
$consumerSecret = '74c5fd430cf1242a527f6223aebd42d30464be22';

We construct security settings that ensure Author API is initialised on the intended domain.

$security = [
    'domain'       => $_SERVER['SERVER_NAME'],
    'consumer_key' => $consumerKey
];

Now we call LearnositySDK's Init() helper to construct our Author API configuration parameters, and sign them securely with the $security and $consumerSecret parameters. $init-generate() returns us a JSON blob of signed config params.

$Init = new Init('authoraide', $security, $consumer_secret, $request);
$signedRequest = $Init->generate();
?>

Web page content

We've got our set of signed configuration parameters, so now we can start outputting our page content. The page can be as simple or as complex as needed, using arbitrary HTML, JavaScript and your frameworks of choice to render the desired product experience.

This example uses a plain HTML page for simplicity, but the important parts are:

  • A div with id="XXX", where XXX corresponds to the id parameter of the report that should be rendered there.
  • The <script src="https://authoraide.learnosity.com"></script> tag, which includes Learnosity's Author Aide API on the page and makes the global LearnosityAuthorAide object available.
  • The call to LearnosityAuthorAide.init(), which initiates Author Aide API to inject the reports into the page.
  • In our case, we use PHP to dynamically echo the contents of our signed JSON blob of $initOptions into the JavaScript so it can be passed to init().
<!DOCTYPE html>
<html>
    <head>
<link rel="stylesheet" type="text/css" href="../css/style.css">
    </head>

    <body>

        <script src="https://authoraide.learnosity.com"></script>

        <div id="aiApp"></div>

        <script>
            const initializationObject = <?php echo $signedRequest; ?>;

           const authorAideApp = LearnosityAuthorAide.init(
               initializationObject,
               '#aiApp',
               {
                   readyListener: function() {
                       console.log('Author aide API is ready.');
                       window.authorAideApp = authorAideApp;
                   }
               }
           );
        </script>

    </body>
</html>

 

Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.