【问题标题】:Order ID in shopify webhooksshopify webhook 中的订单 ID
【发布时间】:2018-11-05 17:37:41
【问题描述】:

我正在尝试将我的应用与 shopify 商店集成。到目前为止,我配置了 webhook 以在某些系统事件上向我的应用发送数据 - 例如创建订单。

除了一个例外,一切都很好——我不明白如何从这些 webhook 中获取订单 ID。它们中不存在任何看起来像订单 ID 的参数我稍后需要在任何请求中使用它来 shopify 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": []
}

看起来可能很方便的唯一参数是tokenorder_number,但token 可能也不是我想要的,就像order_number。第三个是 id 但是,根据 shopify 文档,id 是一个 webhook id,而不是 order id。你知道如何从 webhook 中获取这样的 order ID 吗?

【问题讨论】:

  • 你从哪里得到这个? “基于shopify docs,id是webhook id,不是order id” 实际上,“id”是order id。

标签: shopify webhooks


【解决方案1】:

就像 webhook 来自的域一样,订单 ID 位于标头中。这会帮助你。只需从那里获取订单 ID,然后继续。

示例:

domain = request.env['HTTP_X_SHOPIFY_SHOP_DOMAIN']
order_id = request.env['HTTP_X_SHOPIFY_ORDER_ID']

【讨论】:

  • 非常感谢!我不明白为什么身体里没有这些信息:)
  • 它在体内。 'id' 是订单 id(不是你说的 webhook id)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多