Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
I am writing an app to change tags on specific orders. I notice that while the order graphql specifies tags as string[], you update via string of the form `,` however the order created/updated webhook passes it as a string delimited by `, `.
So a mutation:
mutation orderUpdate($input: OrderInput!) {
orderUpdate(input: $input) {
order {
id,
tags,
}
userErrors {
field
message
}
}
}
{
"input": {
"id": "gid://shopify/Order/3222829039791",
"tags": "asdf,bsdf,gsdf"
}
}
Gives a resulting webhook call of:
"tags": "asdf, bsdf, gsdf",
I presume this means I just need to split on `,` and strip the resulting string?
You are correct. Tags are stored as a String, comma-delimited. So when you read them, you split into an array and when you write them you join with a comma.
@HunkyBill - the root of the question is more how spaces are handled. It looks like shopify does a trim internally.
That is if I invoke the orderUpdate graphql with the string "asdf, two_spaces" the resulting tags are "asdf", "two_spaces" it strips the leading characters from the second tag. This is totally fine - just want to make sure this is expected and not going to change
makes sense. use strip. I see this kind of thing all the time with webhook data. lots and lots of crazy... inject emoji and other weird characters... makes for fun times.