Javascript SDK
SDK for Javascript
This SDK is a Javascript based library that makes it easy to use the Axis LMS API in your Javascript or Node.js code.
You can download the SDK files here:
https://files.atrixware.com/files/axis/resources/axisapi.sdk.js.zip
Basic Usage
Here is a basic example of calling the Axis API using the Javascript SDK. This example sets the return type as XML but you can also set it to return as JSON. Note that your code will also have to include the endpoint and API key not shown in this example. Check out the template.html and example html files in the Javascript SDK for more details:
axisapi.call({
endpoint: "user/getlist",
p1: "admin",
returntype: "xml",
oncomplete: function() {
var result = axisapi.return_value;
var items = result.getElementsByTagName( "result" );
for ( i = 0; i < items.length; i++ ) {
console.log(items[i].childNodes[0].nodeValue);
}
}
});
While the Axis API natively returns results as XML, using the SDK you can set the result to be returned as either XML or JSON. You can use the built-in Javascript functions to parse through either kind of result. When converted to JSON, the data could be in a few different formats (flat object, or an object of arrays for example, depending on the complexity of the data).
When handling tagged data which some endpoints return back as values to some nodes, the Javascript SDK has a function to help you parse through the results of that kind of data structure:
axisapi.get_tag_data($tagname, $string)
This function will return the data value for $tagname
in the $string
containing tagged data.
The SDK also has a few variables you can access. These are useful due to the async nature of the language:
axisapi.return_value
This variable holds the return value of the last API call, and is typically used in the oncomplete function of your API call.
axisapi.last_endpoint
This variable holds the last API endpoint, and is in sync with the axisapi.return_value
above.
The Javascript SDK consists of several library files you will use in your projects ( axisapi.sdk.js and template.html ) and also a few example files that demonstrate how to use API commands with return values in XML and JSON formats.
To set up the Javascript SDK in a browser-based environment, follow these steps:
-
Create a folder on your web server to put the files.
-
Unzip the SDK files, and copy to the folder on your web server.
-
To try the sample files, open them up and populate the required fields with data for your LMS.
To use the Javascript SDK in a Node.js server environment:
In production scenarios, you will want to use this SDK in a Node.js setting. You will want to bring in the /lib/ folder and the axisapi.sdk.js inside it into your coding environment, make sure you include jQuery as well (see this article if you need assisance: https://www.geeksforgeeks.org/how-to-use-jquery-with-node-js/). Use the code in the template.html file as a starting point to write your API calls. See the example files for code on processing both XML and JSON results.