Skip to content

Update Product if Product already exist #50

Answered by JanikHalder
JanikHalder asked this question in Help
Discussion options

You must be logged in to vote

I found an easy solution for this problem.

You can check if a product exist by using:

const product = await swell.get('/products', {
where: {
uniqueIdentifier: value,
},
limit: 25,
page: 1,
})

this returns

{
count: numberOfItems,
results: [items],
page: 1,
}

Now you can check if numberOfItems === 0

If it is zero you have to create a new Product,
if it is 1 you get the id of the product by using product.results[0].id and now you can use this id to update the product.

Hope this helps.

Best, Janik

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ericingram
Comment options

Answer selected by JanikHalder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants