I have a task to retrieve the current value of order fields (for example, tags) when receiving the orders/updated webhook in order to store this field in a metafield.
I want to update the metafield only when the field value has actually changed. To achieve this, I compare the value of tags in the webhook payload with the metafield value. If they differ, I fetch the latest tags value via a GraphQL query and write it into the metafield.
The issue arises because of the difference in formats: the webhook payload provides the value as "tag 1, tag 2", while the GraphQL query returns it as ["tag 1", "tag 2"].
Could you please clarify:
Is it possible to change the webhook payload format so that it matches the GraphQL format?
If the answer to the first question is no, is it acceptable for a public app to fetch the current field value not via GraphQL API but via the REST API (which is deprecated and may be removed in the future)? Would using REST API in the public app affect eligibility for the Build for Shopify status?
No, you can’t change the webhook payload format to match GraphQL. Webhooks maintain their REST-like format ("tag 1, tag 2" as a comma-separated string) while GraphQL returns arrays (["tag 1", "tag 2"]) for backward compatibility reasons. This format difference is by design and outlined in the webhook reference documentation.
As for built for Shopify, as the REST api’s are legacy, I would suggest sticking to only using Graphql.
What you could do instead instead of REST, you can easily solve this with format conversion. ie: const webhookTagsArray = webhookPayload.tags.split(', ') to convert the webhook string into a GraphQL-compatible array for comparison.
You could even consider using webhook filters to trigger only when tags actually change, then handle the format conversion in your webhook handler.
I saw another post about updating the webhook payloads to GraphQL. Are you aware of this project, and can you please share the progress of the work?
I am working on an integration with Odoo and Shopify, but it has been very challenging since I need to develop 2 sets of logic to handle data received from webhooks(REST) and manual requests(GraphQL).
Since Shopify already marked the REST Admin API as legacy and deprecated, why is the reason of still being it in the webhook?
Don’t judge.. but I basically just ignore the contents of the Webhook and fetch it afresh using GraphQL. The Webhook doesn’t always contain the detail I need, and it saves a lot of hassle and logic around the two formats.
As Liam mentioned in that post, and changes or announcements will be noted in the developers changelog and will have sufficient notice to make any necessary changes.
I think Ceri’s suggestion would work good in this case. You can use the webhook as a trigger for a graphql API call that you need to make, so you don’t need to develop 2 sets of logic. Then if the payload is migrated to Graphql, the migration will be much easier for you.
Alternatively, if there are only certain fields you need, you can use filters on webhooks to request only the relevant fields Filter your events