Custom API for updating products

If I understand correctly what you are trying to do - internal REST call is odd.
I also import products from external source - but I do it by using these two calls - depending on my control hash value and if product exists or not.

await strapi.db.query('api::product.product').update(query)
await strapi.db.query('api::product.product').create(query)

query for update and create are the same - but the create one does not have “where” part

const query = {
  where: {
    id: existing_products[new_data.import_code].id
  },
  data: {
    ...new_data,
    import_date_time: new Date().toISOString(),
    import_hash: hash
  }
}

Also - notice the hash value - I calculate it from “new_data” and import only if it different - so you do not have to update the record if nothing changed.

Hope that helps.

1 Like