Getting Started
Introduction and Assumptions
Reading this document assumes you are familiar with:
- Common RESTful HTTP response codes.
- JSON serialization.
- Using the WebSocket, and retrieving your ghostId.
- How to retrieve the id of ReportResults you wish to download.
Previously, the session identifier was being passed in the quesy string using the argument name ghost, but it is now required to be ghostId.
Running a Report
To create report results, use the WebSocket's mergeReportResult command. The report will be run and results created as soon as the merge completes. Each ReportType has its own logic, will summarize differently, and require different ReportParameterTypes.
For example, all reports require startDate and endDate parameters, and the Tag Summary also requires the tags parameter. For a full list of required and optional parameters, please see the Reports API Reference.
To target only specific assets, set the ReportResult.options.targets to a valid search expression..
Here's a process flow:
- Reconnect to the WebSocket and re-use your ghostId.
If you don't have a valid ghostId, send login and retrieve it.
- Send subscribe command with the reportResult SubscriptionType.
- Send a mergeReportResult command, and check the mergeReportResultResponse for the id.
- Wait for reportResultMerged messages (with the id from step 3) and check the status for completed (or failed).
Use the progress value of the object to see the report's progress.
- Once you know the report is complete, sent a separate HTTP GET for the results to this service.
Retrieving Results as a large JSON object
Downloading the raw, un-transformed results is easy. Once the report is finished processing, send a GET request for the results here:
https://reports.fleetfreedom.com/json/reportResultId?ghostId=ghostId&breakdown=boolean
Parameter | Type | Default | Definition |
---|---|---|---|
breakdown | boolean | false | When building results, the raw, unaltered data used to calculate the results can be included by specifying breakdown=true. However, this can make the results file very large and may not be necessary for all applications. |
After sending the GET command, you will receive one of the following responses:
Code | Status | Definition |
---|---|---|
200 | OK | Your request was processed successfully and theresponse body contains the results object. The object contains all the same members as the ReportResult object, but also includes two more; summary and breakdown. For a full description of the format, see the JSON Format in the Reports API Reference. |
302 | Found | The report is not yet finished. Use the WebSocket to check on the status and progress of the report before requesting the results again. You can also check the Location and Retry-After headers. |
401 | Unauthorized | Invalid session or no ghostId provided |
403 | Forbidden | Permission to view this report result is denied |
404 | Not Found | The report result does not exist, or was deleted |
* | Any other | An error has occurred. Check the response body for more details, and if necessary, contact technical support. |
Downloading Results
Completed results are not stored in a particular format as user preferences vary greatly and have an effect on the display of those results. Users can choose a different language or prefer measurements in kilometres or miles. So in order to download the results in a chosen file format, you must request that they are built. Once built, the results are available again instantly.
Downloading results is a two or three step process.
- Request a build for a given Report Results
- Optional: Check the progress and status of the build
- Retrieve the built file
Step 1: Request a build
Requesting a build requires a GET command of the following format:
https://reports.fleetfreedom.com/<format>/reportResultId?ghostId=ghostId&breakdown=boolean&rebuild=boolean&redirect=boolean
For example, if I want the results as a spreadsheet including the detailed breakdown:
https://reports.fleetfreedom.com/xlsx/42?ghostId=<ghostId>&breakdown=true&redirect=true
Parameter | Type | Default | Definition |
---|---|---|---|
breakdown | boolean | false | When building results, the raw, unaltered data used to calculate the results can be included by specifying breakdown=true. However, this can make the results file very large and may not be necessary for all applications. |
rebuild | boolean | false | After a result is built once, it is available again instantly. However, in some rare cases you may want to clear the previous build and re-process the results. |
redirect | boolean | true | When true, automatically sends a Location header in the response when appropriate. When false, does not automatically redirect. |
Format | Description |
---|---|
xhtml | A displayable web-page of the results designed to work with the Fleet Freedom front-end. This format changes regularly to keep up-to-date with Fleet Freedom's features and requirements. |
xlsx | A spreadsheet that can be used to further filter and sort the results. |
After sending the GET command, you will receive one of the following responses:
Code | Status | Definition |
---|---|---|
202 | Accepted | Your request was accepted an a build is being processed. Check the response headers for Location for a URL to retrieve the completed results. You can also check the Retry-After for an estimated timeout (in seconds) before the completed build is ready. The X-Queue-Token header contains a GUID you can use to get the completed build and check its progress/status. Note: If the redirect parameter is false, then the Location header will not be present. |
302 | Found | The build is ready, check the Location for a URL to retrieve the completed results. |
401 | Unauthorized | Invalid session or no ghostId provided |
403 | Forbidden | Permission to view this report result is denied |
404 | Not Found | The report result does not exist, or was deleted |
* | Any other | An error has occurred. Check the response body for more details, and if necessary, contact technical support. |
Step 2: Check build progress
https://reports.fleetfreedom.com/queue/<queue-token>/status?ghostId=<ghostId>
Once a build is in progress, you can check the status of the build before going to get the produced file. The response body is a JSON object with two keys; status and progress.
Check the Retry-After response header for a reasonable time limit between checks on build status.
The progress is a floating-point number between 0 and 1.
The status can be one of three values:
Value | Definition |
---|---|
queued | The build has been added to the processor queue or is being actively created. |
completed | The build process has finished. You can now download the file. |
failed | An error occurred during file creation, please download the file to check the error. If necessary, contact technical support. |
Examples
{
"status": "queued",
"progress": 0.0
}
{
"status": "queued",
"progress": 0.429173
}
{
"status": "completed",
"progress": 1.0
}
Code | Status | Definition |
---|---|---|
200 | OK | The status of the build was successfully retrieved. Please Note: Even if the build has failed, this response will be 200 OK since the command to get the status was successful. |
400 | Bad Request | The queue-token provided is invalid. |
401 | Unauthorized | Invalid session or no ghostId provided |
403 | Forbidden | Permission to view this report result build is denied |
404 | Not Found | The build does not exist |
* | Any other | An error has occurred. Check the response body for more details, and if necessary, contact technical support. |
Step 3: Download the file
https://reports.fleetfreedom.com/queue/<queue-token>?ghostId=<ghostId>
After the build completes, the file can be downloaded using the build queue-token given in step 1.
Code | Status | Definition |
---|---|---|
200 | OK | The Content-Type will match the requested format, and the response body is the completed file. |
202 | Found | The build is not completed, check the Retry-After header for a hint as to how long you should wait before trying again. It is recommended you check status (see step 2) if you expect the results to be very large. |
204 | No Content | The build completed, but there were no results to include in the file. |
400 | Bad Request | The queue-token provided is invalid |
401 | Unauthorized | Invalid session or no ghostId provided |
403 | Forbidden | Permission to view this report result build is denied |
404 | Not Found | The build does not exist |
* | Any other | An error has occurred. Check the response body for more details, and if necessary, contact technical support. |
Cancel a build
https://reports.fleetfreedom.com/queue/<queue-token>/cancel?ghostId=<ghostId>
If you no longer need the results file, or wish to free some resources for your user, you can request a build be cancelled.
The processor chooses resources based on the session and user making the requests. If you request many builds at once, the processor may not begin to prepare them all in order to keep resources available for other users.
Code | Status | Definition |
---|---|---|
200 | OK | The build was stopped and any generated parts of the file have been deleted. |
400 | Bad Request | The queue-token provided is invalid |
401 | Unauthorized | Invalid session or no ghostId provided |
403 | Forbidden | Permission to view this report result build is denied |
404 | Not Found | The build does not exist |
* | Any other | An error has occurred. Check the response body for more details, and if necessary, contact technical support. |