Enhance Your E-commerce Experience with Taobao API Actions

3 Jun 2025
Enhance Your E-commerce Experience with Taobao API Actions

The Taobao Product And Shop Search API offers a suite of powerful Cognitive Actions that streamline the way developers can interact with one of the largest e-commerce platforms in the world. With this API, you can easily retrieve product details, search shops, and analyze logistics pricing, all while leveraging multi-language support to cater to a global audience. The benefits include faster integration, simplified data access, and enhanced user experiences, making it an ideal solution for developers looking to enhance their e-commerce applications.

Use Cases

Imagine you are building an e-commerce application that needs to display product information from Taobao or help users find the best shipping options for their purchases. The Taobao API provides the tools to achieve that with ease. Whether you're developing a marketplace, a price comparison tool, or an inventory management system, these actions can significantly reduce the time and effort required to access and manage Taobao data.

Query Taobao Logistic Price

The Query Taobao Logistic Price action allows you to retrieve pricing information for logistics services on Taobao based on a specific address and item identifier. This is particularly useful for applications that need to provide shipping cost estimations to users before they finalize their purchases.

  • Input Requirements:
    • addressInfo: A JSON string containing the country, city, district, and state for the address.
    • itemIdentifier: A unique string that identifies the item.
  • Expected Output:
    • A response containing the item ID, shipping fee, currency, and additional logistical details.
  • Use Cases for this specific action: Use this action when you want to provide users with accurate shipping costs based on their location and the item they wish to purchase. This can help in reducing cart abandonment rates by informing users of total costs upfront.

```python
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "1f9f98a2-23f0-4d65-8d30-a25ccf30d801" # Action ID for: Query Taobao Logistic Price

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "addressInfo": "{country: '中国', city: '杭州市', district: '余杭区', state: '浙江省'}",
  "itemIdentifier": "795529916500"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Search Taobao Shop with Translation
The **Search Taobao Shop with Translation** action performs searches on Taobao shops while supporting multi-language translation. This allows developers to customize their queries by sorting, filtering, and selecting the store, language, and pagination options.

- **Input Requirements:** 
  - `language`: The language code for the response.
  - `storeId`: The unique identifier for the store.
  - Additional optional parameters include sorting order, filters, page number, and items per page.

- **Expected Output:** 
  - A list of shops with relevant product information, including prices, titles, shop names, and promotional displays.

- **Use Cases for this specific action:** 
  Implement this action when you want to enable users to search for shops in their preferred language, making it easier for international customers to navigate and understand offerings on Taobao.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "43f3ae50-2705-472b-b7dd-33b4550e678e" # Action ID for: Search Taobao Shop with Translation

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "sort": "PRICE_ASC",
  "storeId": "57496020",
  "language": "en",
  "pageNumber": "1",
  "numberOfItemsPerPage": "10"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Fetch Taobao Product Details
The **Fetch Taobao Product Details** action retrieves detailed product information from Taobao’s platform, including multiple language translations. This is essential for applications that require comprehensive product data for display.

- **Input Requirements:** 
  - `itemIdentifier`: A unique string identifier for the item.
  - `language`: The language code for the request.

- **Expected Output:** 
  - Detailed product data including price, images, specifications, and SKU lists.

- **Use Cases for this specific action:** 
  Use this action to display detailed product descriptions, images, and specifications on your site or application, enhancing the shopping experience for users by providing all necessary information at their fingertips.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "55cb3642-743c-4f7c-a8b5-f1ef3b5fca72" # Action ID for: Fetch Taobao Product Details

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "language": "en",
  "itemIdentifier": "795529916500"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Perform Taobao Image Search
The **Perform Taobao Image Search** action enables image-based product searches on Taobao, supporting multi-language translation. This innovative approach allows users to search for products using images instead of keywords.

- **Input Requirements:** 
  - `pictureUrl`: The URL of the image to be searched.
  - `language`: The language code for the response.

- **Expected Output:** 
  - A response indicating the success of the operation, along with any matching products found.

- **Use Cases for this specific action:** 
  This action is perfect for apps that want to provide a visual search feature, allowing users to upload images of products they like and quickly find similar items available on Taobao.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "9536c2eb-d5da-4769-acd9-8707d4580a6b" # Action ID for: Perform Taobao Image Search

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "language": "en",
  "pictureUrl": "https://img.alicdn.com/bao/uploaded/i3/684174095/O1CN019WLF1n1g7YYWtonEu_!!0-item_pic.jpg"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Execute Taobao Keyword Search
The **Execute Taobao Keyword Search** action allows for detailed keyword searches on Taobao, supporting multi-language translation. Developers can customize searches with filters, sorting orders, and pagination options.

- **Input Requirements:** 
  - `keyword`: The main keyword for searching.
  - `language`: The language code for the query.
  - Additional optional parameters include sorting order, filters, page size, and page number.

- **Expected Output:** 
  - A list of products matching the search criteria, including details like price, title, and shop name.

- **Use Cases for this specific action:** 
  Ideal for applications that need to implement search functionality, this action allows users to find products easily and efficiently, enhancing their overall shopping experience.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "db6886de-6d2d-425f-93fc-d6c35c799720" # Action ID for: Execute Taobao Keyword Search

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "sort": "PRICE_ASC",
  "keyword": "手机",
  "language": "en",
  "pageSize": "10",
  "pageNumber": "1"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Conclusion
The Taobao Product And Shop Search API provides developers with a robust toolkit for integrating e-commerce functionalities into their applications. With actions designed for logistics pricing, shop searches, product details, image searches, and keyword searches, developers can create seamless user experiences that cater to a global audience. By leveraging these actions, you can enhance your applications, improve customer satisfaction, and ultimately drive more sales. 

The next steps for developers include obtaining a Cognitive Actions API key and familiarizing themselves with the API documentation to start implementing these features in their applications.