In an earlier post, I showed how to use the Blackbaud K12 API interface for their “ON” products using PowerShell. Now, I’ll show you how to use PHP to do the same thing. I use PHP for all of my web applications.
There are a lot of ways to access a REST based API using PHP, but they can depend on which version of PHP, how it is installed, what security limitations your host has, and who knows what else. To make my life simple, I use the Httpful PHP library. To use it, download the PHP archive file to your web server. Then “include” the archive and you’re good to go.
include_once ('./httpful.phar'); # This loads the Httpful client $schoolWebsite = "https://my_school.myschoolapp.com" # website used to login to the "ON" products $apiUser = "my_username"; $apiPassword = "my_password"; # Authenticate to the API, and get a token to use for further calls $uri = "$schoolWebsite/api/authentication/login/?username=". $apiUser . "&password=" . $apiPassword . "&format=json"; $response = \Httpful\Request::get($uri)->expectsJson() ->send(); # Store the token as a variable so it's handy $token = $response->body->{"Token"}; # Call the list API $uri = $schoolWebsite . "/api/list/49748/?t=" . $token . "&format=json"; $response = \Httpful\Request::get($uri)-> send(); $listResults = $response->body; var_dump($listResults);