大数跨境

现在,事件(Events)已支持 Metafield 触发器及其他附加主题

现在,事件(Events)已支持 Metafield 触发器及其他附加主题 Shopify电商独立站
2026-07-21
1
导读:应用现在可以订阅 Order、Collection、Inventory Item、Inventory Shipment、Location 的事件,并可以订阅 Product、Order、Custome

应用现在可以订阅以下事件: Order、 Collection、 InventoryItem、 InventoryShipment、 Location,并可以订阅以下对象的 metafield 更改: Product、 订单、 Customer、 Collection 和 Location。 ProductVariant 通过 Product 主题支持 Product Variant metafields: Product 主题。

这为应用提供了一种精确的方式来响应更多对象和自定义数据更改。应用可以针对triggers中重要的字段,查询发生更改的资源,并避免仅为了在事件处理程序中比较有效负载而订阅每个资源更新。

支持两种$app元字段和普通元字段。访问控制仍然适用,因此应用必须拥有对元字段的访问权限才能订阅更改并获取查询到的数据。例如,应用可以在shopify.app.toml中订阅两个特定的产品元字段,并使用query_variables来获取实际发生更改的元字段:

[events] api_version = "unstable" [[events.subscription]] handle = "product_material_sync" topic = "Product" actions = ["update"] triggers = [ "product.metafield(namespace: 'custom', key: 'material').value", "product.metafield(namespace: '$app', key: 'sourcing_status').value" ] uri = "/events/product" query = """ query ProductMetafieldSync( $productId: ID! $metafieldNamespace: String! $metafieldKey: String! ) { product(id: $productId) { id title metafield(namespace: $metafieldNamespace, key: $metafieldKey) { namespace key value type } } } """

当这些 metafield 之一发生变化时,应用会收到它们设计的负载:

{ "topic": "Product", "action": "update", "handle": "product_material_sync", "data": { "product": { "id": "gid://shopify/Product/1234567890", "title": "Canvas Tote", "metafield": { "namespace": "custom", "key": "material", "value": "Cotton", "type": "single_line_text_field" } } }, "fields_changed": [ "product.metafield(namespace: 'custom', key: 'material').value" ], "query_variables": { "productId": "gid://shopify/Product/1234567890", "metafieldNamespace": "custom", "metafieldKey": "material" } }

如果您的订阅没有triggers,或者订阅了父级触发器(如product),它现在也可以接收对受支持资源的元字段更改事件。要仅接收特定的元字段更改,请为您的应用所需的命名空间和键添加目标元字段触发器。

在开发者预览期间,事件仍在unstable API 版本中可用。对于尚未支持的主题,请继续在shopify.app.toml中与 Events 一起使用 Webhooks。

了解更多关于

  • 事件: https://shopify.dev/docs/apps/build/events
  • 订单: https://shopify.dev/docs/api/events/latest/order
  • 集合: https://shopify.dev/docs/api/events/latest/collection
  • 库存项: https://shopify.dev/docs/api/events/latest/intentory-item
  • 库存发货: https://shopify.dev/docs/api/events/latest/inventory-shipment
  • 位置: https://shopify.dev/docs/api/events/latest/location
【声明】内容源于网络
0
0
Shopify电商独立站
1234
内容 7163
粉丝 0
Shopify电商独立站 1234
总阅读95.5k
粉丝0
内容7.2k