The Token service is a compulsory RESTful API for integrated users to retrieve a token which will be submitted as part of the request header for authentication purposes on every API request call. A valid token must be provided within each API call. Tokens are only valid for 20 minutes. The Token API will be added by default to all APPs created.
REVEAL integration users are provided with a REST username and password. The integration credentials will not be the same as the user’s email address and password used to access the integration manager portal. Every REST integration credential is associated with one REVEAL account.
To retrieve a successful token, the integration username and password needs to be converted to BASE64, as shown in the sample below.
<?php $username = 'USERNAME'; $password = 'PASSWORD'; $FIM_endpoint = 'https://fim.api.ENV.fleetmatics.com/token'; //Call method and set variable to authorization string $token = get_token($FIM_endpoint, $username, $password); echo $token; function get_token($url, $username, $password) { //Create necessary headers for REST call $headers = array(); $headers[] = make_authorization_header($username, $password); //Send to function to Base64 encode $headers[] = 'Accept: text/plain'; //Authorization token comes back as plain text $session = curl_init($url); //Initialize transfer with URL curl_setopt($session, , false); //Exclude header info in response curl_setopt($session, , true); //Return transfer as a string of the return value of curl_exec() curl_setopt($session, , $headers); //Pass in headers //Execute transfer of $session $response = curl_exec($session); //Get http code outcome of the #session transfer $http_code = curl_getinfo($session, ); //Measure false response/error if($response === false) { echo 'Error: '. curl_error($session); } //ALWAYS close transfer connection curl_close($session); //Evaluate variable for non 200(OK) http code if($http_code !== 200) { echo 'Error: Http Status Code returned '.$http_code; } return $response; } function make_authorization_header($username, $password) { //Base64 encode username:password; note: the ':' must be present between them $encodedString = base64_encode($username.':'.$password); //Return concatenated Authorization string return 'Authorization: Basic '.$encodedString; } ?>
To download source code for this example, click HERE.
All sample code is provided by Fleetmatics, A Verizon Company, for illustrative purposes only. These examples have not been thoroughly tested under all conditions. Fleetmatics, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. All programs contained herein are provided to you “AS IS” without any warranties of any kind.