我正在尝试将我的应用与shopify商店整合。到目前为止,我配置了webhooks以在某些系统事件上向我的应用程序发送数据 - 比如创建订单。
除了一个例外,一切都工作得很好 - 我无法理解如何从这些webhook中获取订单ID。其中没有任何param存在,看起来像订单ID 我后来需要在任何请求购买API以检索订单信息时使用。
示例webhook(订单创建事件):
{
"id": 488245657691,
"email": "",
"closed_at": null,
"created_at": "2018-05-10T14:05:02-04:00",
"updated_at": "2018-05-10T14:05:03-04:00",
"number": 6,
"note": "raz dwa trzy",
"token": "xxx",
"gateway": "manual",
"test": false,
"total_price": "2000.00",
"subtotal_price": "2000.00",
"total_weight": 0,
"total_tax": "373.98",
"taxes_included": true,
"currency": "PLN",
"financial_status": "paid",
"confirmed": true,
"total_discounts": "0.00",
"total_line_items_price": "2000.00",
"cart_token": null,
"buyer_accepts_marketing": false,
"name": "#1006",
"referring_site": null,
"landing_site": null,
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "555.69",
"checkout_token": null,
"reference": null,
"user_id":"",
"location_id":"",
"source_identifier": null,
"source_url": null,
"processed_at": "2018-05-10T14:05:02-04:00",
"device_id": null,
"phone": null,
"customer_locale": null,
"app_id": "",
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1006,
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"manual"
],
"processing_method": "manual",
"checkout_id": null,
"source_name": "shopify_draft_order",
"fulfillment_status": null,
"tax_lines": [
{
"title": "VAT",
"price": "373.98",
"rate": 0.23
}
],
"tags": "",
"contact_email": null,
"order_status_url": "",
"line_items": [
{
"id": 1241199411291,
"variant_id": 8135591723099,
"title": "Above elbow glass",
"quantity": 1,
"price": "2000.00",
"sku": "",
"variant_title": null,
"vendor": "",
"fulfillment_service": "manual",
"product_id": 750373666907,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"name": "Above elbow glass",
"variant_inventory_management": null,
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"tax_lines": [
{
"title": "VAT",
"price": "373.98",
"rate": 0.23
}
]
}
],
"shipping_lines": [],
"fulfillments": [],
"refunds": []
}
token
和order_number
看起来很方便的唯一参数,但token
可能也不是我想要的,就像order_number
一样。第三个是id
但是,基于shopify文档,id
是一个webhook ID,而不是订单ID。您对我如何从中获取此类订单ID有任何想法webhook?
答案 0 :(得分:1)
就像webhook来自的域一样,订单ID在标题中。这会帮助你。只需从那里获取订单ID,然后继续。
示例:
domain = request.env['HTTP_X_SHOPIFY_SHOP_DOMAIN']
order_id = request.env['HTTP_X_SHOPIFY_ORDER_ID']