Using the Taobao API to Build a Category-Based Product Recommendation System

1. Introduction

In e-commerce, when users view a product, being able to recommend similar products based on its category can significantly improve user engagement and conversion rates. This is known as category-driven recommendations — a common strategy used by online stores to boost browsing time and sales.

In this article, we'll explore how to use Taobao’s APIs such as taobao.itemcats.get and taobao.items.list.get to:

  • Retrieve a product’s category (CID)

  • Query related products within that category

  • Build a basic recommendation module

  • Apply category recommendations in UI/UX, such as “You Might Also Like”

2. Taobao API Overview: Category-Related Endpoints

Here are the key APIs used in this project:

API Name

Purpose

taobao.itemcats.get

Retrieve category details (including hierarchy)

taobao.items.list.get

Get a list of items by category ID

taobao.item.get

Get details of a single product (including its category)

3. Workflow for Category-Based Recommendations

  1. Use taobao.item.get to get a product’s category ID (CID)

  2. Use taobao.itemcats.get to get category metadata for display

  3. Use taobao.items.list.get to fetch related items under the same category

  4. Render recommended products in the frontend interface

4. Python Implementation

Step 1: Get a Product's Category ID

def get_item_cid(num_iid):

params = {

'method': 'taobao.item.get',

'api_key': API_KEY,

'num_iid': num_iid,

'fields': 'title,cid',

'timestamp': int(time.time())

}

params['signature'] = generate_signature(params)

response = requests.get(API_URL, params=params)

item = response.json()['item_get_response']['item']

return item['cid'], item['title']

This function retrieves the product’s category ID and title based on its numeric ID.

Step 2: Fetch the Category Name

def get_category_name(cid):

params = {

'method': 'taobao.itemcats.get',

'api_key': API_KEY,

'cids': cid,

'fields': 'cid,name,parent_cid,is_parent',

'timestamp': int(time.time())

}

params['signature'] = generate_signature(params)

response = requests.get(API_URL, params=params)

return response.json()['itemcats_get_response']['item_cats'][0]['name']

We use this to display meaningful category names in the UI instead of just numeric IDs.

Step 3: Retrieve Similar Products from the Same Category

def get_similar_items(cid, count=5):

params = {

'method': 'taobao.items.list.get',

'api_key': API_KEY,

'cid': cid,

'fields': 'title,num_iid,price,pic_url',

'sort': 'volume_desc', # sort by sales volume

'page_no': 1,

'page_size': count,

'timestamp': int(time.time())

}

params['signature'] = generate_signature(params)

response = requests.get(API_URL, params=params)

return response.json()['items_list_get_response']['items']

This function returns the most popular items in the same category, ideal for generating recommendations.

Step 4: Assemble and Display the Recommendation Block

def display_recommendations(num_iid):

cid, title = get_item_cid(num_iid)

category_name = get_category_name(cid)

items = get_similar_items(cid)

print(f"? Based on the product \"{title}\", here are more suggestions from the same category ({category_name}):")

for item in items:

print(f"- {item['title']} | NT${item['price']} | Link: https://item.taobao.com/item.htm?id={item['num_iid']}")

This function brings everything together and outputs related products under the same category.


5. Frontend Module Design Tips

Feature

Description

Category Label

Show current category to clarify why items are recommended

Product Card

Display image, title, price, and link

Sorting Options

Let users sort by “Newest,” “Best-selling,” “Price: Low to High,” etc.

Search Integration

Combine user browsing history and category info for better targeting

6. Advanced Use Cases and Optimization

Strategy

Description

Multi-category merging

If a product belongs to multiple categories, recommend across them

Category bestseller list

Cache daily top-selling items per category

API caching

Reduce API calls for hot categories using local storage or Redis

User preference learning

Combine with behavior data for personalized suggestions

7. Conclusion

Using the Taobao API to build a category-driven product recommendation system is both practical and scalable. It boosts user engagement and directly supports sales optimization.

In This Article, We Learned How To:

  • Use API endpoints to fetch product categories

  • Retrieve related items based on category ID

  • Display contextual product suggestions

  • Extend logic to support multi-category, sales-based, and behavioral targeting

Articles related to APIs :

If you need the Taobao API, feel free to contact us : support@luckdata.com