Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Webhook for order updated sends tags as strings

Webhook for order updated sends tags as strings

longinoa
Excursionist
16 1 0

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?

Replies 3 (3)

HunkyBill
Shopify Partner
4853 60 571

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.

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
longinoa
Excursionist
16 1 0

@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

HunkyBill
Shopify Partner
4853 60 571

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.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com