0
votes

I'm trying to integrate my app with shopify shop. So far, i configured webhooks to send data to my app on certain system events - like creating an order.

Everything is working just great with one exception - i can't understand how to get the order ID from those webhooks. There is no any param present in them that looks like an order id which i later need to use in any requests to shopify API to retrieve info about the order.

Example webhook (order-created event):

{
  "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": []
}

The only params that looks like might be handy are token and order_number but token is probably nor what i'm looking for, just like the order_number. Third one is id but, based on shopify docs, id is a webhook id, not order id. Do you have any idea on how can i obtain such order ID from the webhook?

1
Where do you get this from? "based on shopify docs, id is a webhook id, not order id" Actually, "id" is the order id.trollkotze

1 Answers

1
votes

Just like the domain the webhook is coming from, the order ID is in the header. That will help you out. Simply grab the order ID from there, and move on.

example:

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