# Foomatic Routing and Distance API ## Overview Foomatic is a route planning company that provides services for businesses that need to optimize product delivery routes in big cities and rural areas or complex, multi-week long trips for traveling salespeople. This is the API Reference guide for Foomatic which provides detailed information on how to interact with Foomatic Platform through its API. To make Foomatic's route optimization one of the best, we must have a fully optimized API which allows our customers to identify the best possible route without requiring hefty computing power or risking long wait times. This will allow for on-the-fly redirecting drivers from problematic areas increasing their safety and reliability. Foomatic utilizes a REST API to calculate the shortest road distance between two sets of geographic coordinates, which can be presented as a link to Foomatic page with route details, or a simple distance prediction in kilometers. To make use of this API, you must first request an API key here: [Get your Key](https://foomatic.ca/requestkey), after which you can make a `GET` request to the endpoint provided below. **Endpoint:** `foomatic.ca/route/request_route` --- ## Request Parameters The following parameters need to be sent with the GET request to retrieve data. * **`start_lat`** (float): Starting latitude in decimal degrees. * **`start_long`** (float): Starting longitude in decimal degrees. * **`end_lat`** (float): End latitude in decimal degrees. * **`end_long`** (float): End longitude in decimal degrees. * **`api_key`** (string): Your super secret key. * **`map_link`** (boolean): **Optional** If included (i.e., `&map_link=true`), the API will return a URL link to the Foomatic route visualizer page, otherwise, the API defaults to returning the raw total distance. --- ## Example Requests & Responses ### 1. Requesting a Map Route URL Using this request will redirected the user to a visual map of their route. (Note the addition of `&map_link=true` at the end of the URL) **Sample Request:** ``` foomatic.ca/route/request_route?start_lat=44.6488&start_long=-63.5752&end_lat=46.0878&end_long=-64.7782&api_key=YOUR_SUPER_SECRET_KEY&map_link=true ``` **Sample Response:** ```json { "status": "success", "data": { "route_url": "[https://foomatic.ca/app/view-map?origin=44.6488,-63.5752&dest=46.0878,-64.7782](https://foomatic.ca/app/view-map?origin=44.6488,-63.5752&dest=46.0878,-64.7782)", "description": "Click this link to view your route on the map." } } ``` ### 2. Requesting Raw Distance Data Using this request will yield the travel distance between points, recommended for use within your own applications for simplicity of processing. **Sample Request:** ``` foomatic.ca/route/request_route?start_lat=44.6488&start_long=-63.5752&end_lat=46.0878&end_long=-64.7782&api_key=YOUR_SUPER_SECRET_KEY ``` **Sample Response:** ```json { "status": "success", "message": "Distance calculated successfully.", "data": { "distance": 186.24, "unit": "km", "origin": { "latitude": 44.6488, "longitude": -63.5752 }, "destination": { "latitude": 46.0878, "longitude": -64.7782 } } } ``` ### 3. **Sample Error Response:** ```json { "status": "error", "message": "Missing coordinate parameter", "error_code": "MISSING_PARAMETER", "requirements":{ "origin": [ "start_lat", "start_long" ], "destination": [ "end_lat", "end_long" ], "API_key":[ "SUPER_SECRET_KEY" ] } } ``` ### 4. **Status/Error codes:** * **"success":** no errors indicated. * **"error":** error indicated, look at error code for description. * **"MISSING_PARAMETER":** One of the 4 required parameters is missing or invalid. Verify that all coordinates are input properly and re-request. * **"INVALID_AUTH":** Your API key is invalid or not authorized, verify that the key you used is correct and if you are still having this problem contact our support to check if your key wasn't deactivated or expired or request a new key. ### 5. Usage limits Free keys are limited to 5 requests per day, while keys registered to corporate or paid-access users have no daily limit. All keys have 480 second waiting period between requests to prevent DDOS style attacks.