Marketplaces Scripts

OnBuy API

12min

Introduction

This section of the marketplaces documentation will explain how we utilize the OnBuy API to list products for clients. The OnBuy API is based on the REST architecture. You can find more information about the API here

I will provide an overview of how the code operates, and the process we adhere to ensure products are listed seamlessly.

Code Overview

Authentication

To access the OnBuy API, you need to obtain authentication keys (secret and consumer key) from your client's OnBuy API. Once you have these keys, you can fetch an access token and start interacting with the API.

Python


Products

The OnBuy marketplace operates as a catalogue, which means that an item belonging to another client cannot be listed twice. However, if an item is already listed, a client can list the same item under the original seller’s listing. New products can be listed directly on the marketplace, provided that their EAN does not already exist on the OnBuy Marketplace. This ensures that there are no duplicate listings for the same product.

The Process we use to list products on OnBuy Marketplace is:

Get Products

1.Fetch the products from our Database that are to be listed on OnBuy using the get_listing_data method which we have looked at in the marketplaces Docs

2.Retrieve all the products currently listed on the client’s account - For this step we use the endpoint https://api.onbuy.com/v2/listings. The get_products function is designed to fetch the list of products asynchronously as this endpoint is paginated and fetching the proucst synchronously will be a slow process. After the products are fetched they are save to a csv file. More explantation on this endpoint.

Python


Note this just a code snippet showing how the function works, You can the see real implementation of the code in our Github repository

3.Compare these products with our data and the data obtained from OnBuy to identify new and old products - We save the data from our database and OnBuy into CSV files and use the pandas library to analyze new and old products. Since the SKU serves as the common identifier, it is the basis for our comparison. As a result of this comparison, we generate two files: one that contains the data already listed in the client's account and another that comprises data not yet existing in the client's account.

Python


4.Perform an EAN check on OnBuy to verify if the EAN of these products is already in use - For this we use the endpoint https://api.onbuy.com/v2/products. The get_existing_OPC function is designed to asynchronously retrieve existing EAN data and add it to a DataFrame. It takes advantage of asynchronous programming to efficiently fetch and process a large amount of data. More explantation on this endpoint

Python


To run both the get_products and get_product_OPC we create separate functions in the onbuy_main.py module to run them in order to rtetrieve the data

-get_already_listed_barcodes - this function runs the get_existing_OPC function and creates files from the data returned from the function. this function creates a file containing new products that are not yet listed on OnBuy and another file containing products that are already listed on OnBuy but not on the client’s account.

Python


-get_onbuy_products - This function is used to run the get_products function and create a file from the data returned.

Python


Create Products

This Part explains how the new products and already listed products are listed to the OnBuy marketplace.

1.New products - To do this in the API we use the endpoint https://api.onbuy.com/v2/products. The create_new_products function is designed to list new products on OnBuy using data from a CSV file. It processes the product data in the CSV file, generates the required payload, and sends the data to the OnBuy API for listing. More explantation on this endpoint

Python


Example Usage

Python


2.Already Listed Products - we list products under sellers who already have listed the product on onbuy. we use the endpoint https://api.onbuy.com/v2/listings. The process_product_listings function is designed to interact with product listings on OnBuy by reading data from a CSV file and performing either updates or creating new listings, depending on the specified action. More explantation on this endpoint

Python


Example Usage

Python


This Doc provides a general overview of how to interact with the OnBuy API for both retrieving and listing products.

Main Module

The main module is used to combine different methods for execution and scheduling. It ensures the smooth flow of the listing process.

Python


Conclusion

To understand the process better go through the OnBuy documentaion and also the code in the repository. this present a good understanding of the Listing Process.