Javascript Buy SDK : an unknown error has occurred.

Highlighted
Tourist
10 0 1

Hello Developers,

I m facing this error while i m fetching the products from my shopify store using react js through JS BUY SDK.

But i m getting this such error "an unknown error has occurred."

Code as below : 

import Client from "shopify-buy";
class ProductListing extends Component {
  constructor(props) {
    super(props);
    this.state = {
      ready: false,
    };
  }
  client = Client.buildClient({
    domain: "SHOP DOMAIN GIVEN", 
    storefrontAccessToken: "TOKEN GIVEN",
  });

  async componentDidMount() {
    console.log("0");
    await this.loadProducts();
  }
  loadProducts = async () => {
    console.log("1");
    var productsss = await this.client.product.fetch("4458139451523");
    console.log("productsss");
    console.log("4");
  };
  render() {
    console.log("0.0");
}

Please help me out in this.

Thanks in Advance.

Highlighted
Shopify Staff
Shopify Staff
516 100 97

Hey @identix 

 

Looking at the Shopify aspects of your code - it looks like you are utilizing the wrong ID. The Storefront API utilizes a different ID than the Admin API. Here is an example to run through where you can grab your products: https://github.com/Shopify/js-buy-sdk#fetching-products.

 

You can also test out your queries first in GraphiQL or any API client you use: https://shopify.dev/docs/storefront-api/getting-started#using-graphiql

 

 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
Highlighted
Tourist
10 0 1

@vix You mean to say that i am using wrong id for product?


0 Likes
Highlighted
Shopify Staff
Shopify Staff
516 100 97

yes, it appears so from your example code. Let me know if you resolved this. 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


Highlighted
Tourist
10 0 1

Hello Vix, 
Sorry for the inconvenience, here when i have seen the code i came to know that this is only providing storefront product. So is there any SDK for react to fetch product using admin api.

I am having admin api token. 
Thanks,
 

0 Likes