Search API Connector Documentation

Print

Import MapBox Optimization Data to Google Sheets

CONTENTS

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.

  1. 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/
  • Profiles:
    • mapbox/driving-traffic
    • mapbox/driving
    • mapbox/walking
    • mapbox/cycling

To retrieve directions you should use the following API link:

GET https://api.mapbox.com/optimized-trips/v1/{profile}/{coordinates}?access_token=YOUR-TOKEN

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).

  1. Open up Google Sheets and click Add-ons > API Connector > Open.
  2. In the Create tab, enter the API URL constructed like this:
https://api.mapbox.com/optimized-trips/v1/mapbox/driving/-122.42,37.78;-122.45,37.91;-122.49,37.81;-122.40,37.92;-122.48,37.73?access_token=ENTER-YOUR-TOKEN

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:
https://api.mapbox.com/optimized-trips/v1/mapbox/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219;13.418555,52.523215?destination=last&roundtrip=true&access_token=YOUR-API-TOKEN
  • Request an optimized cycling roundtrip with four coordinates, starting at the first coordinate pair and ending at the last coordinate pair:
https://api.mapbox.com/optimized-trips/v1/mapbox/cycling/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219;13.418555,52.523215?source=first&destination=last&roundtrip=true&access_token=YOUR-API-TOKEN
  • Request an optimized car trip with four coordinates and one distributions constraint where the last given coordinate must be visited before the second:
https://api.mapbox.com/optimized-trips/v1/mapbox/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219;13.418555,52.523215?roundtrip=true&distributions=3,1&access_token=YOUR-API-TOKEN

PART 5: LIMITATIONS

  • It can be requested:
    • maximum of 12 points per request
    • maximum 25 distributions per request
    • maximum 300 requests per minute

Leave a Comment