Print

Import eBay Data to Google Sheets

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

eBay uses a non-standard implementation of OAuth so we'll get our token through some custom requests rather than using the OAuth manager.

Contents

Before You Begin

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

Part 1: Get your eBay Client ID & Secret

  1. Sign up for a developer account. It will take 1-2 business days to get approved.
  2. Log in to the eBay Developer site and navigate to Your Account > Application Keys . Name your application and click Create a keyset for either the Sandbox or Production environments, depending on the environment you're targeting.
    ebay-createkeys
  3. Note your Client ID and Client Secret
    ebay-keys
  4. One more step: for OAuth, we'll need to encode these values to Base 64 (i.e. basic authentication), so let's do that now. Enter your credentials in the format client ID:client secret into this form (i.e. your client ID, then a colon, and then your client secret).

    The encoding script runs in your browser, and none of your credentials are seen or stored by this site.

     

  5. Copy the result and keep it handy. This will be referred to as your_encoded_credentials, and we'll use this value later.

Part 2: Get Your Auth Code

Now that we have the encoded client ID & secret, let's get our auth code. We'll need to use the auth code within a few minutes of retrieving it, so if you'd prefer not to rush, you can set up (but not run) the token request in part 3 first.

  1. Navigate to the User Access Tokens section of the site.
    ebay-menu-token
  2. As before choose whether you'd like to access product or test environment
  3. Scroll down the page to the Get a Token from eBay via Your Application section. Click +Add eBay Redirect URL
    ebay-addredirect
  4. You'll be prompted to fill out some information about yourself or your company. Do so and click Save to return to the redirect URL form.
  5. Select OAuth. Leave the other fields blank. Click Save
    ebay-saveredirect
  6. Now click Test Sign-In
    ebay-testsignin
  7. You'll be asked to log into eBay (if you aren't already), and will then see a code parameter in the URL bar starting with v%5E1. Copy this value, it's our auth code.
    ebay-copycode
  8. One more step: the code above is URL encoded, but we'll need to send back the URL-decoded value. Decode your code using your tool of choice, e.g. https://meyerweb.com/eric/tools/dencoder/. We'll call this your_auth_code, and will use it shortly.
You can only click Test Sign-In for an auth code once. If you click it again, you'll get a different code, and that new code will produce an error. If you need a new auth code, you'll need to delete that RuName and start over from +Add eBay Redirect URL.

Part 3: Get Your Token

We now have all the pieces we need to get our token. We'll need to move a little quickly here as the code above is only valid for a few minutes.

In the configuration below, replace your_encoded_credentials with your encoded client ID & secret from part 1, replace your_auth_code with your decoded auth code, and replace your_RuName with the RuName given to you in the redirect URL form (see screenshot).
ebay-RuName

Configuration

  1. Open up Google Sheets and click Extensions > API Connector > Open
  2. Fill in the request form like this:
    • Application: Custom
    • Method: POST
    • Request URL: https://api.ebay.com/identity/v1/oauth2/token
    • Headers:
      • Authorization: Basic your_encoded_credentials
    • Request body: {"grant_type":"authorization_code","redirect_uri":"your_RuName","code":"your_auth_code"}
  3. Hit Run and you should see your access token in cell A1. Finally! 🙂

Part 4: Get eBay Data in Sheets

You can see the full list of available endpoints and parameters in the API documentation, along with a nice API Explorer tool. Here's an example request. Substitute in the token value from the access_token field (for convenience, I referenced the cell containing it).

The token will last for 2 hours, see the next section for how to refresh it after that.

  • Application: Custom
  • Method: GET
  • Request URL: https://api.ebay.com/buy/browse/v1/item_summary/search?q=drone&limit=3
  • Headers:
    • Authorization: Bearer your_token

Part 5: Refresh the Access Token

The original token you retrieve will last for 7200 seconds, or 2 hours.

However, that same response also contains a refresh token that can be used to fetch new access tokens for 47304000 seconds (1.5 years). That means every time you need a new token, run the following request:

  • Application: Custom
  • Method: POST
  • Request URL: https://api.ebay.com/identity/v1/oauth2/token
  • Headers:
    • Authorization: Basic encoded_credentials
  • Request body: {"grant_type":"refresh_token","redirect_uri":"your_RuName","refresh_token":"your_refresh_token"}

This request will never change, as it always uses the same refresh_token from the original response. You can schedule it so that it always runs immediately before your data request, thus keeping your access active. In that data request, reference the cell containing the access token so it always plugs in the new token dynamically, and you won't need to update your requests again (for 1.5 years).

Part 6: API Documentation

Official API Documentation: https://developer.ebay.com/develop/apis/restful-apis

eBay API Explorer Tool: https://developer.ebay.com/my/api_test_tool?index=0

Leave a Comment

Jump To