PHP Example Code
We have written a small PHP class you can use with your code to make it easy to consume the Axis REST API.
To get started, download the Axis REST API Class Files.
To use the class, simply include the axisAPI.php
file in your code.
There is an example.php
file included in the download with more additional details on the example code below, but for quick reference, here are a few examples using the PHP class:
/* ************************************************************
create an API object
these commands should be included in every page
the API is being used
************************************************************** */
include "axisAPI.php";
$api = new axisAPI();
$api->setServerDomain("{www.yourlmssystem.com}");
$api->setAPIKey("{key}");
$api->useBearerTokens();
/* ************************************************************ */
/* sample call to a GET endpoint, no filtering */
$result = $api->get("/certifications/list/all/");
/* sample call to a GET endpoint, with filtering
this example will get fields username, first_name and last_name for each user
where their username is not 'admin' and their username excludes 'custom'.
accepts 'equals', 'not', 'contains' and 'excludes' as comparisons
*/
$api->addFieldFilter(["username", "first_name", "last_name"]);
$api->addUserFilter("username", "not", "admin");
$api->addUserFilter("username", "excludes", "custom");
$result = $api->get("/users/filtered/");
if ( $result->success ) {
echo $result->json;
}
$api->clearFilters();
/* sample call to a POST endpoint */
$result = $api->post("/courses/enrollments/6/1/", ["start" => "20230101", "end" => "20231231"]);
/* sample call to a DELETE endpoint */
$result = $api->delete("/courses/enrollments/6/1/");
/* sample call to a PUT endpoint */
$result = $api->put("/users/1", ["last_name" => "Adminner"]);