GraphQL Webhook Body Shape

EugeneKim
Shopify Partner
60 3 27

What is the expected shape of the webhook body that will be sent from Shopify when creating a webhook via the GraphQL API?

I haven't been able to find this kind of into in the GraphQL documentation. It's frustratingly bare:

https://shopify.dev/docs/admin-api/graphql/reference/object/webhooksubscription

 

Can I rely on the expected body of the webhooks created via the REST API? What about webhook topics that aren't available in the REST API e.g. APP_SUBSCRIPTIONS_UPDATE?

Replies 4 (4)

mikedasilva
Shopify Staff (Retired)
61 7 12

Hi @EugeneKim,

When creating a webhook subscription through the GraphQL API, the response you get really depends on what your query looks like. For example, if you create a webhook subscription with the following mutation:

mutation {
  eventBridgeWebhookSubscriptionCreate(
    topic: ORDERS_CREATE
    webhookSubscription: {
      arn: "arn:aws:events:us-east-1::event-source/aws.partner/shopify.com/XXXXX/example-name-here"
      format: JSON
  })
  {
    webhookSubscription {
      id
    }
    userErrors {
      message
    }
  }
}

 

 

You'll get a response that also includes the webhookSubscription with "id" because you specified to return that in the query above.

{
    "data": {
        "eventBridgeWebhookSubscriptionCreate": {
            "webhookSubscription": {
                "id": "gid://shopify/WebhookSubscription/1234567890"
            },
            "userErrors": []
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 10,
            "actualQueryCost": 10,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 990,
                "restoreRate": 50.0
            }
        }
    }
}

 

You can add other fields that you'd like returned when creating a subscription, you just have to modify that query. 

 

Cheers,

Mike

To learn more visit the Shopify Help Center or the Community Blog.

EugeneKim
Shopify Partner
60 3 27

Hi @mikedasilva ,

Forgive me if my question wasn't clear. I'm not asking about the shape of the mutation response that gets returned to me when creating a webhook subscription. My question is about the shape of the object that Shopify will send through to the WebhookSubscription.endpoint. This is not documented anywhere in the GraphQL Admin API docs so I'd like to be pointed to some documentation around that.

Thanks!

mikedasilva
Shopify Staff (Retired)
61 7 12

Hi @EugeneKim,

Ah yes, sorry, I misunderstood the question. The payload that you receive will be the same as what you would get when you subscribe to the webhook via the rest API. So as you may have already come across, there's a list of events and topics with example responses available here https://shopify.dev/docs/admin-api/rest/reference/events/webhook.

I'll forward along the feedback about that information missing from the GraphQL reference docs.

Cheers,

Mike

 

To learn more visit the Shopify Help Center or the Community Blog.

EugeneKim
Shopify Partner
60 3 27

@mikedasilva this is good to know for the webhooks that the REST API covers. However, there are others that can only be created using the GraphQL API e.g. APP_SUBSCRIPTIONS_UPDATE that have no documentation around them.

Could you provide a reference for the webhook body shapes for all the webhooks that are only available via the GraphQL API?

Thank you