Shopify在GraphQL中提供批量操作,可以一次执行所有更新。但是,目前REST API不支持它。
我正在尝试做一个临时系统,使用API更新客户的标签。
我有一个包含2个字段的数据帧-要应用的电子邮件和标签:
+----------------------+-----------+
| **email** | **tag** |
+----------------------+-----------+
| example@gmail.com | active |
+----------------------+-----------+
| example@yahoo.com | cancelled |
+----------------------+-----------+
| example@inbox.com | example |
+----------------------+-----------+
| example@whatever.com | some tag |
+----------------------+-----------+
我使用以下代码迭代客户并更新他们的标签:
for i in df.index:
customer_string=str(shopify.Customer.search(query=df['email'][i])) #find id based on email
if customer_string!='[]':
customer_id=customer_string[10:23]
customer=shopify.Customer.find(customer_id)
customer.tags=str(df['tag'][i])
customer.save()
如果要定期更新这些标签,会有更有效的方法吗?
https://shopify.dev/docs/api/usage/bulk-operations/queries