Get an API Key

To use the Roads API you must have an API key. The API key is a unique identifier that is used to authenticate requests associated with your project for usage and billing purposes. To learn more about API keys, see the API Key Best Practices and the FAQs.

Get the API key

You must have at least one API key associated with your project.

To get an API key:

  1. Go to the Google Cloud Platform Console.
  2. From the Project drop-down menu, select or create the project for which you want to add an API key.
  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key (an encrypted string).
  5. Click Close.
    The new API key is listed on the Credentials page under API keys.
    (Remember to restrict the API key before using it in production.)

Add the API key to your request

You must include an API key with every Roads API request. In the following example, replace YOUR_API_KEY with your API key (the encrypted string).

https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.12907|-35.28099,149.12929|-35.28144,149.12984|-35.28194,149.13003|-35.28282,149.12956|-35.28302,149.12881|-35.28473,149.12836 &interpolate=true &key=YOUR_API_KEY

Restrict the API key

Before moving your project to production, we strongly recommended that you restrict your API key. Restrictions help ensure only authorized requests are made with your API key. To learn more, see the FAQs.

To restrict an API key:

  1. Go to the Google Cloud Platform Console.
  2. From the Project drop-down menu, select the project that contains the API key you want to secure.
  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click the name of the API key that you want to secure.
  5. On the Restrict and rename API key page, set the restrictions:
    • Application restrictions
      • Select IP addresses (web servers, cron jobs, etc.).
      • Add the server IP addresses (see the examples).
    • API restrictions
      • Select Restrict key.
      • Click Select APIs and select Roads API.
        (If there are other enabled APIs you want to use with this key, select them as well.)
    • Click SAVE.

Premium Plan customers

To use the Roads API, Premium Plan customers must authenticate requests using an API key. By using an API key you can:

Get more information on reports available to Premium Plan customers.

To get an API key:

  1. Go to the Google Cloud Platform Console.
  2. From the Project drop-down menu, select the project created for you when you purchased the Premium Plan. The project name starts with Google Maps APIs for Business or Google Maps for Work or Google Maps.

    Note: To have full access to the features in their plan, Premium customers should use the project associated with their Premium account. When you purchased your license, you received the name of your Premium asset in the following format: gme-[company] & proj-[number] ([type]). To ensure you are accessing the correct project, log in to the console as the project owner using console.cloud.google.com/project/number (replace number with your project number). You can locate the project owner in your welcome letter.

  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays the newly created API key (an encrypted string).
  5. Click Close.
    The new API key is listed on the Credentials page under API keys.
    (To continue, see Add the API key to your request and Restrict the API key.)

Troubleshooting authentication issues

If your request is malformed or supplies an invalid signature, the Roads API returns an HTTP 403 (Forbidden) error.

To troubleshoot individual URLs, you can use the URL Signing Debugger. It allows you to quickly validate a URL and signature generated by your application.

Alternatively, Premium Plan customers can troubleshoot individual URLs by logging in to the Google Cloud Support Portal and selecting Resources > Google Maps APIs Premium Plan online tools > URL Signing Debugger for Web Service and Image APIs.

Skicka feedback om ...

Behöver du hjälp? Besök vår supportsida.