Getting meta named object when Fetching data from Commerce js

66 Views Asked by At

I am trying to fetch data from commerce.js by following documentation. After fetching data I am getting a object named Meta.

function fetchProducts() {
  commerce.products.list()
    .then((res) => {console.log("products Data",res);})
    .catch((error) => {console.log('There was an error fetching the products', error);});
}

useEffect(()=>{
  fetchProducts();
}, [])
output == products Data {meta: {…}}meta: {pagination: {…}}[[Prototype]]: Object

I don't know if it is working fine, or there are any mistakes from my side. As per documentation, It is an array of objects not meta.

2

There are 2 best solutions below

0
scrowler On

Robbie from the Commerce.js team here. It looks as if no products are being returned in your account. Do you have any set up?

We have a known issue where the data key, which is normally an array of objects, doesn't get returned when no results are available.

0
RascarCapcak On

Had the same issue fetching a specific product from commerce.js using a query parameter. Turns out the query parameter value had to be all lower case. At least it made it worked in my case. I hope this will help someone.