Introduction to Ebay API with Python: Obtaining keys and accessing the sandbox – Part 1

Ebay is one of the biggest ecommerce sites. Many people use it to search and buy products, and many stores use it to enlarge their audience and expand their business range.

If we want to operate programmatically on Ebay, for example to mass create or modify a set of items, or quickly confront prices, we must use the dedicated application programming interfaces. In this tutorial we will see how to prepare our working environment in order to use python to interact with the Ebay APIs.

In this tutorial you will learn:

  • How to create an Ebay developer account and generate APIs keys
  • What is the Ebay sandbox and how create a sandbox user.
  • How to obtain the Ebay python SDK.

Introduction to Ebay API with python: Obtaining keys and accessing the sandbox - Part 1

Introduction to Ebay API with python: Obtaining keys and accessing the sandbox – Part 1

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Operating system agnostic.
Software git and python3
Other Knowledge of the python programming language and of the basic object oriented concepts.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

What is an API?



API is the acronym of Application Programming Interface. You can thing about an API like a set of programming instructions and procedures which allows a software to connect to a third party service, which provides methods to programmatically perform some kind of tasks.

In this series we will see how to use python to interact with the Ebay APIs, in order to perform operations like searching for items or retrieving detailed informations about them, creating insertions or retrieving statistics about most watched items. In this first article we will see how to create a developer account and generate our API keys, how to create sandbox “test” user, and how to obtain the Ebay python SDK.

Creating an Ebay developer account

The first thing we must do, is to create a developer account, in order to obtain the credential which will be included in the API calls to authenticate us. Navigate to the Ebay developers program website and click on the register voice in the navigation menu. You will be prompted to fill a simple registration form; after you send the information, you will receive a confirmation email.

Creating an Ebay developer account

Creating an Ebay developer account

Once the account is successfully created and confirmed, you can proceed and access the developer website’s functionalities. To generate your API keys and credentials you can navigate to the my keys page. Here you will notice that you can generate keys for both the sandbox and production environment.

The first is a sort of copy of the Ebay website, built with the specific purpose of letting developers perform tests in a safe environment, without having to worry about damaging a real store. The production environment instead is the “real” thing. It should be clear that keys generated for one environment cannot be used to access the other. We will later see how to declare what kind of environment we want to use in our python code.

Each API key set is composed by three elements: the App ID (or Client ID), the Dev ID and the Cert ID (or Secret). To use some specific API, like the Trading API, and to interact with a store, we will also need to get a Token; we will see how to get one later, when we will explore calls related to that API.



Creating a sandbox test user

The next step is to create a sandbox test user. As said before, the sandbox is a copy of the primary site, against we can safely test our applications before moving to production. We can create one or more sandbox “test” users to simulate both buyers and sellers in a transaction.

While you are still on the Ebay developer program site, on the top menu, click on “Tools & samples” -> “Ebay Sandbox” -> “Sandbox user registration”. You will be redirected to a page containing the Register for Sandbox form. This form will be used to create a sandbox user, which, as you can see in the screenshot below, will have the TESTUSER_ prefix:

Registering for an eBay sandbox test user account

Registering for an eBay sandbox test user account When creating the sandbox user we can setup interesting parameters, like the feedback score and the registration date.


Obtaining the python Ebay SDK

The last thing we have to do in order to prepare our working environment is to obtain the python Ebay SDK. The code is hosted on github, therefore we can obtain it right away by running:

$ git clone https://github.com/timotheus/ebaysdk-python

By running the above command we create copy of the repository on our machine. To install the SDK, After you cloned the repository, move inside the created directory and run:

python3 setup.py install --user

Alternatively, the SDK can be installed by using pip, the python package manager, running the following command:

$ pip3 install ebaysdk --user

In both cases we used the --user option, to install the package for the single user, and not globally.

Before starting to explore the available API calls, and the parameters we can pass to each of them, we should notice the ebay.yaml file inside the root of the repository. We can use it to store our credentials instead of providing them directly each time we prepare an API call:

name: ebay_api_config

# Trading API Sandbox - https://www.x.com/developers/ebay/products/trading-api
api.sandbox.ebay.com:
    compatability: 719
    appid: ENTER_YOUR_APPID_HERE
    certid: ENTER_YOUR_CERTID_HERE
    devid: ENTER_YOUR_DEVID_HERE
    token: ENTER_YOUR_TOKEN_HERE

# Trading API - https://www.x.com/developers/ebay/products/trading-api
api.ebay.com:
    compatability: 719
    appid: ENTER_YOUR_APPID_HERE
    certid: ENTER_YOUR_CERTID_HERE
    devid: ENTER_YOUR_DEVID_HERE
    token: ENTER_YOUR_TOKEN_HERE

# Finding API - https://www.x.com/developers/ebay/products/finding-api
svcs.ebay.com:
    appid: ENTER_YOUR_APPID_HERE
    version: 1.0.0

# Shopping API - https://www.x.com/developers/ebay/products/shopping-api
open.api.ebay.com:
    appid: ENTER_YOUR_APPID_HERE
    version: 671


As you see, the file is divided into sections, each containing the the needed credentials for a specific API endpoint. For example, the Finding Api credentials are referenced in the relative section, where we can see that the endpoint is svcs.ebay.com. To use the Finding API all we need to provide is the App ID we generated before. This specific API will be the first one we will explore in the next article of the series.

Conclusions

In this introductory article, we saw how to prepare our working environment in order to use python to interact we the Ebay APIs. We saw how to create a developer account and how to generate our credentials, both for the sandbox and production environments. We also created a sandbox “test” user account, in order to safely perform our tests.

Finally we saw how to retrieve the official Ebay python SDK from github. In the next tutorial of this series we will see how to perform our first calls using the Finding API: stay tuned!

Table of Content



Comments and Discussions
Linux Forum