Update Product if Product already exist #50
-
Hi there, I want to import products into swell from my PIM on a regular base. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I found an easy solution for this problem. You can check if a product exist by using: const product = await swell.get('/products', { this returns { Now you can check if numberOfItems === 0 If it is zero you have to create a new Product, Hope this helps. Best, Janik |
Beta Was this translation helpful? Give feedback.
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