Using the Shopee Open Platform, you can continuously track order statuses and store essential data for operational management and in-depth analysis. This guide will show you how to quickly fetch data from Shopee into n8n or AnyCross, enabling you to expand to other business use cases, such as pushing data to Lark Base, databases, or data warehouses.

Shopee Open Platform Mechanisms:

  1. Push Event: Shopee actively sends data (e.g., new orders, order status changes, shipping updates, or returned items).
  2. REST API: You actively call Shopee’s API with required parameters (e.g., order number) to retrieve detailed information.

Retrieving Shopee Events via Webhook

Webhook is a web address that receives data through HTTP POST. It continuously listens for valid signals sent from other websites.

Steps to Set Up:

  1. Create an account at Shopee Open Platform.
  1. Create an app and successfully register it as a published app.
  2. Configure push events on the Shopee Open Platform interface as follows:
    • Provide a Webhook URL in the Live Callback URL field.
    • Enable the events you want to receive.

You can create the webhook using n8n or AnyCross.

When Shopee pushes an event, the data will be available in the body as JSON. You can process this data further for your specific needs. For example, extract the ordersn (order number) to call APIs and retrieve detailed order information.


Calling Shopee API

This part is slightly more complex, as accessing the data requires authorization from the data owner (shop admin). Once access is granted, you’ll receive an access_token to make API calls.

Shopee API Overview:

The Shopee API documentation provides a comprehensive guide. For example, to retrieve detailed order information, follow these steps:

  1. Path: A parameter for generating a signature (sign). Note whether the method is GET or POST for correct configuration.
  2. Required Parameters: Include these in the URL when making the API call and generating the sign.
  3. Sign: A signature encrypted from the parameters specified in the API documentation.

Generating the Signature (sign)

You can generate the sign by running Python code in an n8n node. (For AnyCross, use JavaScript – instructions will be provided later.) Replace your partner_id, partner_key, access_token, shop_id, and the API path as needed.

import time
import hmac
import hashlib
partner_id = " "
path = "/api/v2/order/get_order_detail"
timest = int(time.time())
access_token = " "
shop_id = " "
tmp_partner_key = " "
tmp_base_string = "%s%s%s%s%s" % (partner_id, path, timest, access_token, shop_id)
base_string = tmp_base_string.encode()
partner_key = tmp_partner_key.encode()
sign = hmac.new(partner_key, base_string, hashlib.sha256).hexdigest()
output = [{'timestamp': timest, 'sign': sign, 'access_token': access_token}]
return output

Example Output: The output from this node can be passed to an HTTP Request node in n8n. Include all required parameters in the request.


API Call Example

For GET requests, include all parameters in the URL in the following format:

https://partner.shopeemobile.com/<path>?<tham-so-1>?<tham-so-2>?<tham-so-3>?<tham-so-n>

Example Result: Once successful, you’ll see a response like this:

https://partner.shopeemobile.com/api/v2/order/get_order_detail?partner_id=12345&timestamp={{ $('sign_order_detail').item.json["timestamp"] }}&access_token={{ $('sign_order_detail').item.json["access_token"] }}&shop_id=456789&sign={{ $('sign_order_detail').item.json["sign"] }}&order_sn_list={{ $('Webhook').item.json["data"]["record"]["fields"]["order_sn"] }}&response_optional_fields=buyer_user_id,buyer_username,recipient_address,item_list,shipping_carrier,payment_method,total_amount

By retrieving data through Shopee’s API, you can automatically access the information provided. However, you may need intermediate steps to clean and process raw data for better usability.

Stay tuned for the next guide where we’ll tackle advanced data processing. See you soon! 🚀

n8n registration: here

Tags:

Leave a Reply