Before you begin

To use Cloud Fleet Routing, you first need to create a Google Cloud project (if you don't already have one) with the email address that was added to the Cloud Fleet Routing API's allowlist. You also need to create a billing account and enable billing for the project.

Next, do the following steps in the Google Cloud console:

  1. Follow the instructions to Enable the Cloud Optimization API.
  2. If you plan to use the Google Map Platform's Distance Matrix API, enable the Google Maps for Fleet Routing.

Authenticating to the API

Fleeting Routing uses OAuth 2.0 for API authentication and authorization. Authentication is the process of determining the identity of a client. The Cloud Optimization API must already be enabled in the authenticated project.

Client libraries can use Application Default Credentials to easily authenticate with Google APIs and send requests to those APIs. With Application Default Credentials, you can test your application locally and deploy it without changing the underlying code. For more information, see Authenticate for using client libraries.

  • Google Cloud: If you're running your application on App Engine or Compute Engine, the environment already provides the default service account's authentication information, so no further setup is required.
  • Local environment: To authenticate your local development environment, the easiest way is to use the Google Cloud CLI.
      gcloud auth application-default login
      gcloud config set project ${PROJECT_NAME}
      gcloud auth application-default set-quota-project ${PROJECT_NAME}
      
  • Non-Google Cloud production environment: If you're running your application elsewhere, download a service account JSON keyfile and set an environment variable to its path.
      export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"
      
  • For more information about authentication, see the Authentication documentation.

    Send requests to the API

    You can send requests to the Cloud Fleet Routing Service using either HTTP requests or the Google API Client Libraries. HTTP requests are the simpler option. You send the data for the problem in JSON format as a POST request. This provides an easy way to test the service or generate quick solutions to a single vehicle routing problem. For information about sending HTTP requests, see the Send HTTP requests with Python quickstart.

    When deploying your production code, we recommend using the Google API Client Libraries for the following reasons:

    • It provides a faster and more robust connection between your client and the API.
    • You can build requests programmatically and conveniently with less code.

    To set up and send requests using the Google API Client Libraries, refer to the quickstarts: