Discussing APIs and development related to customers, discounts, and order management.
I'm looking to add a 'reference number' to my order via the API.
I can either do this as a TAG or a NOTE.
However I only want to it add it once, so I want to do a check and if it already exists then I don't add it.
What's the best way to do this?
If you're doing this via the API I would have expect that you would just keep track of the Order ID in a database.
Since you added the tag, you would be able to store a boolean on if you did in your database. So if for some reason your app processed the order again you would know to skip it.
Depending on what is triggering the action to tag the item (such as a webhook) you would also see the tag in the webhook response so that would help you determine what steps to take.
Now this is all said without knowing the steps you need and why. It's possible none of these are good ideas. If that's the case, come back with more context so we can understand the need more.
Hi Jason so this is how we are adding a tag to our order via API:
await axios.put(`https://${template.storeURL}/admin/api/2021-01/orders/${orderId}.json`, | |
{ | |
"order": { | |
"id": orderId, | |
"tags": `Ref - ${req.body.Status.toLowerCase().replace(/ /g, '_')}` | |
} | |
}, { headers: shopHeaders }); |
This works fine however I want to add 2 more tags:
Application ID - ${AppID}, Reference2 - ${ref2}
So do I pass those in the same request or what is the best way to do it? I would expect to check tags to see if app id and ref2 have been added, if not then add. But I guess with Shopify if it recognises a tag already exists then it would not add it anyway.
Hope that makes sense.
thanks,