Buy SDK

coltrane
New Member
1 0 0

Hey guys!

Brand new to shopify development. I have two public products with some inventory on my store. I created a private app, I initialize the ShopifyBuy client, but client.products.fetchAll() returns an array with this single object - 

[{

     fieldBaseTypes: {edges: "ProductEdge", pageInfo: "PageInfo"}

     implementsNode: false

     kind: "OBJECT"

     name: "ProductConnection"

}]

 

How do I actually access the products via the shopifybuy client? The documentation isn't very helpful.

0 Likes
syf_
Shopify Staff
Shopify Staff
89 20 15

@coltrane you would have to iterate over the elements in the array, and specify what field of the product you want. The code snippet below prints the products ids to the console.

client.product.fetchAll().then((products) => {
    // Do something with the products
    for (const product of products){
      console.log(product.id) //print product id
    }
  });

 

Best,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes