Import MapBox Optimization Data to Google Sheets
- Before You Begin
- Part 1: Get your Mapbox API Token
- Part 2: Create your API Request URL
- Part 3: Pull MapBox API data into Sheets
- Part 4: More Example API URLs
- Part 5: Limitations
BEFORE YOU BEGIN
Click here to install the API Connector add-on from the Google Marketplace.
PART 1: GET YOUR MAPBOX API TOKEN
Optimization MapBox API returns a duration-optimized route between passed points, usually used for planning a route for deliveries in a city (also known as Traveling Salesperson Problem). It belongs to the Navigation MapBox service.
- To start using the MapBox API, we will need to register on the MapBox site. After email confirmation, you will be directed to this page which contains a default public token. However, we would need to make a personal one. Click on the button Create a token.
Name your token and select all the scopes, and then save it.
Now you get your token, that you will need to run your requests!
PART 2: CREATE YOUR API REQUEST URL
To create API requests, we will use some examples provided in the MapBox Optimization API documentation.
- API root: https://api.mapbox.com/optimized-trips/v1/
To retrieve directions you should use the following API link:
PART 3: PULL MAPBOX API DATA INTO GOOGLE SHEETS
In this example, we will request an optimized cat trip between points: (-122.42, 37.78), (-122.45, 37.91), (-122.49, 37.81), (-122.40, 37.92), and (-122.48, 37.73).
- Open up Google Sheets and click Add-ons > API Connector > Open.
- In the Create tab, enter the API URL constructed like this:
3. Now create a new tab, give it a name and click Set current to use that tab as your data destination.
4. Give a name to your request and click run!
5. Now the requested data will appear!
PART 4: MORE EXAMPLE API URLS
In the API documentation, a list of optional parameters is provided, such as specifying the starting or ending location of a trip. We highly encourage you to explore all of them!
- Request an optimized car roundtrip with four coordinates, specifying ending at the last coordinate pair:
- Request an optimized cycling roundtrip with four coordinates, starting at the first coordinate pair and ending at the last coordinate pair:
- Request an optimized car trip with four coordinates and one distributions constraint where the last given coordinate must be visited before the second:
PART 5: LIMITATIONS
- It can be requested:
- maximum of 12 points per request
- maximum 25 distributions per request
- maximum 300 requests per minute