You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Shopify GET Orders API无法获取客户姓名等信息求助

获取Shopify订单API中的客户数据

1. 从API返回结构中提取客户字段

Shopify Orders API返回的订单数据里,客户信息嵌套在customer对象下,直接从该对象提取目标字段即可:

  • 名(first name):customer.first_name
  • 姓(last name):customer.last_name
  • 邮箱(email):customer.email
  • 手机号(mobile):customer.phone(该字段存储客户联系电话,通常为手机号)

其他常用客户相关字段:

  • 客户ID:customer.id
  • 客户创建时间:customer.created_at
  • 客户默认地址:customer.default_address(包含街道、城市、邮编等地址信息)

2. 数据提取示例(Python)

以下是处理API返回数据并提取客户信息的代码示例:

import requests

# 替换为你的店铺信息和API凭证
shop_domain = "your-shop.myshopify.com"
api_key = "your-api-key"
api_password = "your-api-password"

api_url = f"https://{api_key}:{api_password}@{shop_domain}/admin/api/2024-01/orders.json?status=any"

response = requests.get(api_url)
orders = response.json().get("orders", [])

for order in orders:
    customer = order.get("customer")
    if not customer:
        continue  # 跳过无关联客户的订单
    
    # 提取字段
    first_name = customer.get("first_name")
    last_name = customer.get("last_name")
    email = customer.get("email")
    mobile = customer.get("phone")
    
    # 输出或处理数据
    print(f"客户: {first_name} {last_name} | 邮箱: {email} | 手机号: {mobile}")

3. 关键注意事项

  • 部分订单可能是访客下单,没有关联customer对象,需先判断该字段是否存在,避免报错
  • 若需更详细的客户数据,可调用/admin/api/2024-01/customers/{customer_id}.json接口,但订单API返回的customer对象已覆盖大部分常用信息
  • 确保你的API凭证拥有read_orders和read_customers权限,否则会返回权限错误

内容的提问来源于stack exchange,提问作者Amit Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 14:04:55