FetchError: Product with id xxx was not found

I tried adding a product I created in the GUI to the cart via code. I used the product id from the database at: site structure/databases/stores/products/inventory item
Where do I get the correct productId from?

Thanks

Below is the code I used to add the product to the cart:

export function add_to_cart(productId){
    let products = [{
    "productId": productId,
    "quantity": 1
  },
  ]
    $w("#shoppingCartIcon1").addToCart(productId).then( () => {
      console.log("Product added");
    } )
    .catch( (error) => {
      console.log(error);
    } );
}

I also tried the newer version with

cart.addProducts(products)

described in addProducts - Velo API Reference - Wix.com

Both returned with

FetchError: Product with id xxx was not found

The function you used got deprecated, you’re better use the new function:
https://www.wix.com/velo/reference/wix-stores/cart/addproducts

  • check and see if the product id exists in the Products collection (field key: _id)

Thank you. Works perfectly. The id field was hidden by default and forgot to check those fields. (If an admin reads this: perhaps it would be a good idea if this wouldn’t be hidden by default or if the id would be visible from the GUI were the products are usually created)

Out of curiosity were would the “inventory item” field, which I tried, be used?

It’s for querying the inventory status (how many are in stock).