The Taobao API allows developers to import search engine information about products listed on China’s largest ecommerce platforms. Taobao is part of the Alibaba group and the API also works with their sister site, Tmall. In 2021, Taobao was ranked as the 8th most trafficked website in the world. The site is published entirely in the Chinese language and requires foreigners to submit business documentation to register. The RapidAPI service offers free access to the Taobao API for web/mobile app developers.
Programmers can use the Taobao API to search the websites to return product and shop information that can be used as part of their application displays. This tutorial will review the PHP, Python, Ruby, and JavaScript code snippets that are required for building endpoints. Developers can connect to the Taobao/Tmall websites using a free API key from RapidAPI. Sign up for a free account at RapidAPI to access the Taobao API service.
1. About the Taobao API Service
Taobao was an early competitor to eBay and Amazon.com in China. Alibaba promoted the platform to popularize their AliPay service to Chinese consumers like PayPal. Twenty years later, Taobao is one of the most popular websites in the world, operating on a hybrid ecommerce model including both auctions and retail product sales. Businesses or individual sellers can register on Taobao and Tmall to sell their goods to the public. Taobao, Tmall, and AliPay earn commissions on sales and transactions.
Taobao product listings include consumer items like technology, clothes, office supplies, home decoration items, furniture, shoes, etc. Taobao and Tmall have a huge collection of products that can be accessed via API for search. Using the Taobao API, developers can retrieve information about each product like price, quantity, shipping, and seller ratings. The Taobao API also returns thumbnails and featured images from products via search for product number or keyword. Developers can use the Taobao API to mine data for machine learning analysis or embed it in websites and mobile app displays.
Says Lifestyle: Complete English Guide To Shopping On Taobao (2021)
The Taobao API is part of the Alibaba Open Platform which includes a SDK and other developer tools. The API has a HTTP gateway which is called through a URL address. The App Key is used to identify the application making the request. A Session Key is implemented to manage OAuth 2.0 authorization and timestamps. The Tmall API is also part of the Alibaba Open Platform. Alibaba offers security and monitoring tools for their API services. The RapidAPI service offers a free API key for Taobao & Tmall access.
2. What is the Taobao API?
The Taobao API is a developer tool that consists of three main elements: Shops search, Item search, and the ability to retrieve a product image by SKU. Programmers can use any keyword to search the Taobao product database via API. For example, sending an API query with the search term “laptops” would return a list of products with basic information about price, shipping, and seller. Developers building in different programming languages can embed this information in their app displays or use it for data mining. The Taobao API allows you to limit results to a specific number of items.
The Taobao API gives programmers the ability to choose whether to search store listings or item listings for a specific keyword. The Shop search feature can be further refined to only display results from a particular seller. In order to use the advanced shop search functionality, you will need to know the Seller ID for the API query. Otherwise the results will return from all shops. The Item search includes both shops and auctions.
To retrieve the product image from Taobao using the API, developers will need to input the Product SKU into the query. This is sent to the base URL of the service using RapidAPI for verification. There are options for the Taobao ecommerce platform, Tmall, and a combined service depending on which base URL is used for the query or which service provider is utilized to access the service. Alibaba now operates over 5000 unique API services for their cloud platforms, with an average of 5 billion daily calls.
Developer Resources: Learn more about Taobao.com and the AliBaba Open Platform.
3. How does the Taobao API work?
The Taobao API is intended to facilitate B2B ecommerce across websites and mobile applications. By making the search facilities open to developers, Alibaba can attain a wider marketing and distribution footprint through ecosystem partners. Web publishers can also build custom advertising displays into applications, or use data mining and machine learning to filter results in advanced search engine platforms. The use of an API to retrieve information about products is more efficient than scraping websites.
The Taobao API requires user verification of the application making the query via the OAuth 2.0 protocol. RapidAPI provides a free API key developers can use to avoid the lengthy sign up and verification process which requires Chinese language support on the Taobao and Tmall websites. Programmers can use AI-driven translation services from AWS, Google, Azure, and startup companies to display results in English automatically, although the quality of the translation will vary depending on the vendor.
RapidAPI offers a playground environment with support for over 20 programming languages that can be used to automatically generate the code needed to query the Taobao API. The results of the endpoints can then be embedded in displays and styles with CSS to match the design of a website. The RESTful API connects over a HTTP connection to transmit the query and results data in real-time whenever a web page or server cron run is loaded. This allows developers to automate website and mobile displays around search results that are driven by keywords. The results are populated by Taobao and Tmall search engine data, delivered in XML format without styling.
The Taobao API: Use API calls to return product listing information with thumbnails.
4. Who is the Taobao API for exactly?
The Taobao API will appeal to two main sets of application developers primarily: media publishers and custom application developers. Media publishers can use the Taobao API to search and retrieve results from the ecommerce site into their blog pages or special promotions. This can be used to highlight a seller’s own products for display on a business website or for affiliate promotions. Custom application developers can import data from Taobao and Tmall to be used in search engine applications or shopping clubs.
Startups are using the Taobao API for data mining of search results and the training of machine learning algorithms. For example, a custom search engine can combine results from eBay, Amazon, Taobao, and Tmall using the service. Displays can then be customized to create shopping apps for consumers that help them find deals on retail items. The use of the Taobao API in advertising is helpful for brands to promote listings on ecommerce platforms within their own websites and mobile applications.
If your business sells products on Taobao or Tmall, the API can be used with the unique Seller ID or Shop ID to list products on your own website. Then customers can link through to the Taobao or Tmall listings for purchase and fulfillment with AliPay. This is an efficient way for small businesses and independent sellers to promote their businesses with web publishing tools. The Taobao API allows results to be displayed within CMS websites running WordPress, Drupal, and Joomla, or in ecommerce store applications.
5. Tutorial: How to Connect to the Taobao API
To connect to the Taobao API, login to RapidAPI and navigate to the playground environment for the service. Under the “Endpoints” tab, there is a reference table with a drop-down menu supporting all of the available web & mobile programming languages. The Taobao API has code snippets available for more than 20 of the most popular programming languages for web design and mobile app development currently.
You can copy and paste the code snippets from RapidAPI directly into your apps with a valid User ID. Use the playground environment to test endpoints and API variables.
PHP Code Snippets:
For PHP applications and websites, there are four different methods that the code can be input into a web page. Developers can use cUrl, HTTP, or a Unirest request.
To embed the Taobao API with cUrl in PHP:
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://taobao-api.p.rapidapi.com/api?q=adidas&api=shop_search_simple", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: taobao-api.p.rapidapi.com", "x-rapidapi-key: insert-your-custom-key-value-here" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
To embed the Taobao API with a HTTP request in PHP:
<?php $request = new HttpRequest(); $request->setUrl('https://taobao-api.p.rapidapi.com/api'); $request->setMethod(HTTP_METH_GET); $request->setQueryData([ 'q' => 'adidas', 'api' => 'shop_search_simple' ]); $request->setHeaders([ 'x-rapidapi-key' => 'insert-your-custom-key-value-here', 'x-rapidapi-host' => 'taobao-api.p.rapidapi.com' ]); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; }
To use an alternative HTTP method with the Taobao API in PHP:
<?php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://taobao-api.p.rapidapi.com/api'); $request->setRequestMethod('GET'); $request->setQuery(new http\QueryString([ 'q' => 'adidas', 'api' => 'shop_search_simple' ])); $request->setHeaders([ 'x-rapidapi-key' => 'insert-your-custom-key-value-here', 'x-rapidapi-host' => 'taobao-api.p.rapidapi.com' ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
Add the Taobao API to your PHP code with a Unirest request:
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://taobao-api.p.rapidapi.com/api?q=adidas&api=shop_search_simple", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: taobao-api.p.rapidapi.com", "x-rapidapi-key: insert-your-custom-key-value-here" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
Make sure to replace the placeholder text with your custom API key from RapidAPI.
Python Code Snippets:
For Python applications and websites, there are three different methods that the Taobao API code can be input into apps. Developers can use the HTTP client, an import request, or a Unirest command to embed the functionality in a display page.
To embed the Taobao API with the HTTP Client in Python:
import http.client conn = http.client.HTTPSConnection("taobao-api.p.rapidapi.com") headers = { 'x-rapidapi-key': "insert-your-custom-key-value-here", 'x-rapidapi-host': "taobao-api.p.rapidapi.com" } conn.request("GET", "/api?q=adidas&api=shop_search_simple", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
To add the Taobao API with a Python import request:
import requests url = "https://taobao-api.p.rapidapi.com/api" querystring = {"q":"adidas","api":"shop_search_simple"} headers = { 'x-rapidapi-key': "insert-your-custom-key-value-here", 'x-rapidapi-host': "taobao-api.p.rapidapi.com" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
To embed the Taobao API with a Unirest command in Python:
import http.client conn = http.client.HTTPSConnection("taobao-api.p.rapidapi.com") headers = { 'x-rapidapi-key': "insert-your-custom-key-value-here", 'x-rapidapi-host': "taobao-api.p.rapidapi.com" } conn.request("GET", "/api?q=adidas&api=shop_search_simple", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
Make sure to replace the placeholder text with your custom API key from RapidAPI.
Ruby Code Snippets:
For Ruby applications and websites, there are two different methods that the Taobao API code can be input into a web page. Developers can use a net::HTTP request or a Unirest command.
To embed the Taobao API with a net::HTTP request in Ruby:
require 'uri' require 'net/http' require 'openssl' url = URI("https://taobao-api.p.rapidapi.com/api?q=adidas&api=shop_search_simple") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'insert-your-custom-key-value-here' request["x-rapidapi-host"] = 'taobao-api.p.rapidapi.com' response = http.request(request) puts response.read_body
To embed the Taobao API with a Unirest command in Ruby:
require 'uri' require 'net/http' require 'openssl' url = URI("https://taobao-api.p.rapidapi.com/api?q=adidas&api=shop_search_simple") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'insert-your-custom-key-value-here' request["x-rapidapi-host"] = 'taobao-api.p.rapidapi.com' response = http.request(request) puts response.read_body
Make sure to replace the placeholder text with your custom API key from RapidAPI.
JavaScript Code Snippets:
For JavaScript applications and websites, there are four different methods that the code can be input into a web page. Developers can use jQuery, fetch, an XML HTTP request, or Axios to build displays for the application.
To embed the Taobao API with jQuery in JavaScript:
const settings = { "async": true, "crossDomain": true, "url": "https://taobao-api.p.rapidapi.com/api?q=adidas&api=shop_search_simple", "method": "GET", "headers": { "x-rapidapi-key": "insert-your-custom-key-value-here", "x-rapidapi-host": "taobao-api.p.rapidapi.com" } }; $.ajax(settings).done(function (response) { console.log(response); });
To add the Taobao API with an XML HTTP request in JavaScript:
const data = null; const xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { console.log(this.responseText); } }); xhr.open("GET", "https://taobao-api.p.rapidapi.com/api?q=adidas&api=shop_search_simple"); xhr.setRequestHeader("x-rapidapi-key", "insert-your-custom-key-value-here"); xhr.setRequestHeader("x-rapidapi-host", "taobao-api.p.rapidapi.com"); xhr.send(data);
To insert the Taobao API with fetch in JavaScript:
fetch("https://taobao-api.p.rapidapi.com/api?q=adidas&api=shop_search_simple", { "method": "GET", "headers": { "x-rapidapi-key": "insert-your-custom-key-value-here", "x-rapidapi-host": "taobao-api.p.rapidapi.com" } }) .then(response => { console.log(response); }) .catch(err => { console.error(err); });
To use the Taobao API with Axios in JavaScript:
import axios from "axios"; const options = { method: 'GET', url: 'https://taobao-api.p.rapidapi.com/api', params: {q: 'adidas', api: 'shop_search_simple'}, headers: { 'x-rapidapi-key': 'insert-your-custom-key-value-here', 'x-rapidapi-host': 'taobao-api.p.rapidapi.com' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); });
Make sure to replace the placeholder text with your custom API key from RapidAPI.
6. Endpoints of the Taobao API
There is almost an unlimited number of endpoints that can be created with the Taobao API. The main two categories are related to keyword search queries on the Shop API and the Item API. If you have the Shop ID or the Product SKU value, then you can submit advanced API queries for more finely-grained filtered results.
The two main search endpoints of the Taobao API are:
- GET Shops Search (Simple)
- GET Items Search
The Taobao Shop API endpoint displays results in a schema with the following categories that are each populated according to the queries of the keyword:
"type":"object" "properties":{1 item "result":{2 items "type":"object" "properties":{11 items "status":{...}1 item "page":{...}2 items "page_size":{...}2 items "total_results":{...}1 item "shop_type":{...}1 item "start_credit":{...}1 item "end_credit":{...}1 item "q":{...}1 item "sort":{...}1 item "item":{...}2 items "execution_time":{...}1 item } } } }
For product search via the Taobao API, the following variables can be used to customize endpoint displays with an Item ID:
For product search using the SKU, the following variable will affect endpoint results:
When searching Taobao and Tmall for items by keyword, the full range of API variables available that filter endpoint search results are:
Developers can use the keyword variables as search terms, limit the number of results, record timestamps and session variables, as well as filter by Shop ID, Seller, or SKU.
7. Alternatives to the Taobao API
RapidAPI hosts a number of different versions of the Taobao API. There are options to search Tmall individually or in combination with Taobao. The Alibaba Open Platform hosts over 5,000 API services. The most popular after Taobao and Tmall is B2B Overseas. Affiliate marketers can look at the Taobaoke program for program support.
- Taobao API: An alternative implementation of the Taobao API by Muhaha2k:
https://rapidapi.com/dataapi/api/taobao-api2 - TaoBao & Tmall Data Service API: Combined search for Taobao & Tmall: https://rapidapi.com/ShowApi/api/taobao-tmall-data-service
- Taobao Advanced API: Add more detail to search queries for better results:
https://rapidapi.com/gabrielius.u/api/taobao-advanced - Taobao Tmall 1688 API: A combined search service for multiple Alibaba sites:
https://rapidapi.com/jaysbum/api/taobao-tmall-1688
These services are recommended for developers who do not speak Chinese and need to access Taobao search through a third-party API service provider, rather than directly registering for a verified account in China. Any results may need further translation. Use an automated translation service from a public cloud provider with AI for best results.
Taobao in Translation: Complete English Guide to Shopping on Taobao and Tmall.
8. What are the benefits of the Taobao API?
The Taobao API allows developers to build custom search engine results for product queries that can assist shoppers in ecommerce applications. Sales and marketers can use the Taobao API to embed product listings in their website pages that link to active marketplace listings. Sellers that are registered on Taobao and Tmall can build web pages that link to their own listings for sidebar and block promotions or special sales.
A major benefit of the Taobao API is that programmers can take the data returned by each API call and style it to match the design of their own applications. This can be done easily in CSS and HTML using div statements to declare class values for fields. Startups are using the Taobao API to build custom search engines or to analyze consumer behavior using artificial intelligence. A custom shopping app can scan Taobao and Tmall for daily deals, then issue alerts when a target price range is identified.
The Taobao API is free to use with 100% service uptime through RapidAPI. The service is rated 9.6/10 and has a 916 ms latency. RapidAPI provides users with a free API key that authorizes your applications with the Alibaba Open Platform using OAuth 2.0 and the base URL value. Programmers can use the advanced API for timestamps and the ability to query with finer-grained search terms. The main benefit of the Taobao API is sales and marketing support with the ecommerce platform to enable wider promotions.
9. Developer Resources for the Taobao API
For more information on the Taobao, Tmall, and Alibaba APIs, take a look at the websites from Hong Kong in English and translate the web content from China using a browser tool. The Alibaba Open Platform has a SDK, wiki, and knowledge base resources. The Taobao AppStore has a list of the advanced API functions available. Alibaba also has a GitHub page with a code repository related to API support.
- Alibaba Open Platform: “Hundreds of millions of registered buyers and millions of registered sellers, with daily trading volume being several billions” (2021):
https://open.alibaba.com/us/portal/resourceDetail?articleId=102693&categoryId=101727 - The Taobao App Store: “Query the subscription relationship of appstore applications (for new multi-version applications, it is recommended to use taobao.vas.subscribe.get)” (2021): https://open.taobao.com/api.htm?cid=1&docId=285&docType=2
- Taobao Open Platform SDK: “Provides API request encapsulation, digest signature, response interpretation, message monitoring and other functions. Using SDK can easily complete API call, API result acquisition, and real-time monitoring of messages.” (2021): https://open.taobao.com/doc.htm?docId=101618&docType=1
- Alibaba GitHub Repository: https://github.com/alibaba
For more background about the Taobao and Tmall ecommerce platforms, see some of the English guides for sellers and buyers listed below:
- Tech in Asia:”Complete English guide to shopping on Taobao and Tmall” (2014):
https://www.techinasia.com/tmall-taobao-english-how-to-guide - Says Lifestyle: “From Sign Up To Payment: Here’s A Complete English Guide To Shopping On Taobao” (2017):
https://says.com/my/lifestyle/english-shopping-guide-taobao
- Cara Crawford: “Taobao Explained, What It Is and Why You Need It” (2017):
https://crawfordcreations.org/taobao-explained/
- Door2Door: “Everything about Taobao – Full Guide” (2020):
https://www.ddpch.com/everything-about-taobao/
- The Page: “What Is The Difference Between Alibaba and Taobao?” (2020):
http://www.thepagemagazine.com/alibaba-and-taobao/
Developers using the Taobao API should be familiar with the use of OAuth 2.0 with RESTful API services. Startups like Precog use the Taobao API with AI analysis to develop better sales and marketing insights on products globally.
10. Summary: Filter Search Results from Taobao & Tmall
The Taobao API allows developers to search products by keyword across sellers, shops, and auctions on the Taobao or Tmall ecommerce platforms. Displays can be customized for websites and mobile apps with CSS. The Taobao API is a RESTful API that connects over HTTP and returns results from a base URL in XML format. You will need to reference a specific Shop or Item ID to retrieve advanced filtered data.
The Taobao API integration is recommended for sales & marketing insight building through data mining of results with machine learning. Taobao, Tmall, and AliPay are the most popular ecommerce solutions in China. The results returned by the Taobao API are in the Chinese language. Developers who publish apps in English will need to use an automated translation service to make the content accessible to readers. Sellers on Taobao and Tmall can use the API to embed shop listings on their website pages as part of SEO promotions or sales.
The RapidAPI service saves developers the time and effort of verifying a Chinese language account to use the Taobao API. Sign up for RapidAPI to receive a free API key for the service. The code snippets above are easy for programmers to insert into PHP, Python, Ruby, and JavaScript application frameworks. Style the search results to match the design of your website or mobile applications, and use the Taobao API for filtered search displays from China’s leading eCommerce platforms. Use ML & AI analysis on search results to build shopping apps for customers.
Leave a Reply