Search API Connector Documentation

Print

Import FedEx Data to Google Sheets

In this guide, we’ll walk through how to import FedEx shipping data directly into Google Sheets, using the API Connector add-on for Sheets.

The FedEx API uses the OAuth client credentials flow. Therefore we will get our token through some custom API requests rather than through API Connector's automatic OAuth2 connection manager (as the OAuth manager currently only supports the authorization code flow).

Contents

Before You Begin

Click here to install the API Connector add-on from the Google Marketplace.

Part 1: Create a FedEx Project

  1. If you haven't already, navigate to https://developer.fedex.com and log in or create an account.
  2. Once you're logged in, click My Projects > +Create A Project
    fedex-createproject
  3. From the Create Project screen, select why you need API access
  4. Choose the APIs to which you'd like to have access
    fedex-selectAPIs

  5. Accept their terms, configure your project, and click Create
    fedex-configure

  6. You should now see test credentials on the page. We'll start with these to show how it works. If you've already done this you can switch to your production key.fedex-keys

Part 2: Get Your Access Token

To get your access token, open API Connector in Google Sheets and create a new request (Extensions > API Connector > Open > Create request).

Set up that request as follows. Note that the below is for the test environment; if you're connecting with production credentials, change the domain from apis-sandbox.fedex.com to apis.fedex.com, so that the request URL is https://apis.fedex.com/oauth/token.

  • Application: Custom
  • Method: POST
  • Request URL: https://apis-sandbox.fedex.com/oauth/token
  • Headers
    • Key = Content-type, Value = application/x-www-form-urlencoded
  • Request body: {"grant_type":"client_credentials", "client_id":"your_api_key", "client_secret":"your_secret_key"}

Substitute in your API key and secret key from above. Name your request and click Run. The whole thing should look like this:
fedex-token

Note the value returned in the access_token field. That's the token we'll use for getting FedEx tracking data. This token will be valid for 1 hour, after that you'll need to run the request again to get a new token.

Part 3: Get FedEx Data in Sheets

You can create a request using any of the endpoints and parameters described in FedEx's documentation. Here's an example to their tracking API. Substitute in your own access token and an actual tracking number (the test tracking numbers provided in their documentation aren't reliable).

As before, the below configuration is for the test environment; if you're connecting with production credentials, change the domain from apis-sandbox.fedex.com to apis.fedex.com.

  • Application: Custom
  • Method: POST
  • Request URL: https://apis-sandbox.fedex.com/track/v1/trackingnumbers
  • Headers
    • Authorization: Bearer your_token
    • Content-Type: application/json
  • Request body: {"trackingInfo":[{"trackingNumberInfo":{"trackingNumber":"794843185271"}}],"includeDetailedScans":true}

For convenience, the example in the screenshot references the token value from cell A2. This means the header doesn't need to be updated as it will automatically pull in the new value each time the access token is refreshed.

Part 4: API Documentation

Official Track API documentation: https://developer.fedex.com/api/en-us/catalog/track/v1/docs.html

14 thoughts on “Import FedEx Data to Google Sheets”

    • Yes! Google provides a scripting language called Apps Script, which is a variation on JavaScript. API Connector and other extensions are built using Apps Script, but you can write your own scripts by opening Sheets and clicking Extensions > Apps Script. Here's one article to get you started.

      Reply
  1. Hi Ana,

    Thanks for the info! On the FedEx API documentation, it provides us a script to use. Do you know how to incorporate that script into Google Sheets? I pasted the script below. Thanks!!

    // 'input' refers to JSON Payload
    var data = JSON.stringify(input);

    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
    console.log(this.responseText);
    }
    });

    xhr.open("POST", "https://apis-sandbox.fedex.com/track/v1/trackingnumbers");
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.setRequestHeader("X-locale", "en_US");
    xhr.setRequestHeader("Authorization", "Bearer ");

    xhr.send(data);

    Reply
    • You'll need to modify that for Apps Script (Apps Script doesn't support XMLHttpRequest(), add a method to fetch the token and input tracking numbers etc, and add some code to trigger the function as well as convert the JSON response from Fedex into a tabular format for Google Sheets. Basically this requires development work. May I ask why you don't want to use the API Connector extension? It already does all of those things, for free.

      Reply
      • My organization doesn't allow third party app of any sort due to security and privacy. I been seeking around different forums and your site is the only one that contains the most information and knowledge. I really wish we an use API connector because your writeup is informative and thorough.

      • Ah, got it, that's too bad. In that case maybe you can try out the open source ImportJSON script, it is a script that you can copy/paste into Apps Script that lets you connect APIs to Google Sheets.

      • Sorry for the confusion, I'm using the api connector privately to understand how it works. I got it to work but i'm not sure how you can do multiple tracking at once.

      • Ah, I see. Fedex's docs say you can input up to 30 tracking numbers at once. Unfortunately they don't give an example of an API call with multiple tracking numbers, but I think the syntax would be like this:
        {"trackingInfo":[{"trackingNumberInfo":{"trackingNumber":"1111111111"}},{"trackingNumberInfo":{"trackingNumber":"22222222"}},{"trackingNumberInfo":{"trackingNumber":"3333333"}}]}

  2. Hi

    I received this error " The given JWT is invalid. Please modify your request and try again."

    What could be the reason?

    Thanks

    Reply
    • That means your access token is invalid. The access token only lasts for an hour, so make sure you fetch and include a fresh, valid token before running your request.

      Reply
  3. Hi,
    I wanna integrate FedEx Rates and Transit Times API with Google Sheets to get an estimate on multiple packages to be shipped. The steps would be the same or there would be any difference? Please let me know. Thank you!!

    Reply

Leave a Comment

Jump To