This article provides you with an example of how bad words filters can be used to prevent multiple designs from having identical text values.
First of all you need to create a token with write scope
Accessing the Kickflip api with a token
Create a webhook for shopify new orders
Create a shopify webhook. Select the order/update webhook.You can either use an app like Zapier or have your own server handle the webhook.
Once you receive the Shopify order webhook you need to retrieve all the items that are Kickflip designs.
Example in nodejs :
const getDesignText = design => {
const summaryItem = design.summary.find(summaryItem => summaryItem.key = 'Write your name')
return summaryItem.value
}
const updateWebhookHandler = async (webhook) => {
// retrieve all design ids
const order = req.body
const kickflipProperties = order.line_items.map(lineItem => {
return lineItem.properties.find(property => propety.name === '_mczr_designId')
}).filter(property => property !== undefined)
// fetch designs from kickflip
const designs = await Promise.all(kickflipProperties.map(property => yourRequestLibrary.get({ headers: { Authorization: `Bearer ${YOUR_API_TOKEN}`}}, `https://api.mycustomizer.com/brands/${companyname}/designs/${property.value}`)
// fetch current bad words list
const badWords = yourRequestLibrary.get({ headers: { Authorization: `Bearer ${YOUR_API_TOKEN}` }}, `https://api.mycustomizer.com/brands/${companyname}/wordfilter`)
// update the list with the new words
const newBadWords = { words: [...badWords.words, designs.map(design => getDesignText(design))] }
// post the new bad words
yourRequestLibrary.post({ headers: { Authorization: `Bearer ${YOUR_API_TOKEN}`}}, `https://api.mycustomizer.com/brands/${companyname}/wordfilter`, newBadWords)
}
NOTE
You could check the Shopify order status to only run the code for orders that are paid.
