ORDERS_CREATE Webhook IncludeFields

TSE_DEV
Shopify Partner
1 0 0

I'm working on an app that includes an ORDERS_CREATE webhook.  When I subscribe to the webhook, one of the fields that I wish the webhook to send my way is "riskLevel", which I've included in the "includeFields" parameter array.  The subscription attempt is accomplished error free (nothing returned in the "userErrors" array), and the returned "includeFields" array lists "riskLevel" along with the other fields I've requested to be returned when the webhook fires.  However, "riskLevel" is not returned in the payload data when the webhook fires.  It is not even included as a field that is set to null; "riskLevel" is simply not there, as if I did not request it via "includeFields".  Is this a bug?  To me, if "riskLevel" cannot be requested as an included field of a ORDERS_CREATE webhook subscription, then I should have gotten a user error when I attempted the subscription.  If "riskLevel" is allowed as an included field and it is simply not set to anything for an given order, I'd think that ["riskLevel":""] should be returned in the webhook data.  Below is the NodeJS code used to subscribe to the webhook, the data returned by the subscription attempt, and an example of what is being returned.  I've tested in one of our live stores to see if this behavior is the same no matter what the actual risk level of an order is (be it "LOW", "MEDIUM", or "HIGH"), and in all cases the result is the same; no "riskLevel" data item included in the data received.

 

 

NodeJS Code that subscribes to ORDERS_CREATE webhook topic:
===========================================================
  const webhookSubscriptionData = await client.query({
    data: {
      "query": `mutation webhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: WebhookSubscriptionInput!) {
        webhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) {
          userErrors {
            field
            message
          }
          webhookSubscription {
            id
            topic
            format
            includeFields
            endpoint {
              __typename
              ... on WebhookHttpEndpoint {
                callbackUrl
              }
            }
          }
        }
      }`,
      "variables": {
        "topic": "ORDERS_CREATE",
        "webhookSubscription": {
          "callbackUrl": "https://mywebsite.com/new-order.php",
          "format": "JSON",
          "includeFields": [
            "id",
            "name",
            "riskLevel"
          ]
        }
      },
    },
  });

The above code returns:
=======================
{
  "userErrors":[],
  "webhookSubscription":{
    "id":"gid://shopify/WebhookSubscription/1234567890",
	"topic":"ORDERS_CREATE",
	"format":"JSON",
	"includeFields":["id","name","riskLevel"],
	"endpoint":{
	  "__typename":"WebhookHttpEndpoint",
	  "callbackUrl":"https://mywebsite/new-order.php"
	}
  }
}

Example logged by "new-order.php":
==================================
--------------------- Webhook Data Received ------------------------
Webhook data = {"id":4881407017026,"name":"#120221"}   <--- No "riskLevel" data item
Webhook payload API Version = 2023-04

 

 

 

Reply 1 (1)

loicnestler
Shopify Partner
4 0 0

Just speculating here, but I'd guess this issue is due to the fact that Shopify calculates it's risk-level asynchronously. As far as I know the order of events is as follows:
Order created -> ORDERS_CREATE Webhooks sent -> Risk level calculated -> Order updated -> ORDERS_UPDATE Webhooks sent.
So you might wanna start listening on update events as well, not just creation-events.