Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid store domain must be provided issue - Storefront API Client #1508

Open
baturalposma opened this issue Sep 15, 2024 · 1 comment
Open

Comments

@baturalposma
Copy link

baturalposma commented Sep 15, 2024

Hi everyone,

Even though I entered the storeDomain and publicAccessToken values ​​correctly and the Shopify support team verified that these values ​​were correct,

I am encountering the error Storefront API Client: a valid store domain must be provided.

Has anyone encountered this problem before? In the application I created, all permissions in the Storefront API access scopes section have been granted.

Can someone with knowledge on this subject help?

Here is my code:

import { createStorefrontApiClient } from '@shopify/storefront-api-client';

const client = createStorefrontApiClient({
  storeDomain: 'http://domain-name.myshopify.com/',
  apiVersion: '2024-07',
  publicAccessToken: 'store-front-api-here'
});

export const fetchCollectionByHandle = async (handle) => {

  const query = `
    query {
      collectionByHandle(handle: "${handle}") {
        id
        title
        products(first: 10) {
          edges {
            node {
              id
              title
              description
              images(first: 1) {
                edges {
                  node {
                    url
                  }
                }
              }
            }
          }
        }
      }
    }
  `;

  try {
    const response = await client.query({
      data: query
    });

    const products = response.data;

    if (!products || products.length === 0) {
      throw new Error('No products found in this collection.');
    }

    return products;
  } catch (error) {
    console.error('Error fetching products by collection handle:', error);
    return [];
  }
};

Thanks,

@sle-c
Copy link
Contributor

sle-c commented Sep 17, 2024

Hi @baturalposma,

What is the shop's domain you're trying to connect to? I used the following script and were able to get the products list .

import { createStorefrontApiClient } from '@shopify/storefront-api-client';

const client = createStorefrontApiClient({
  storeDomain: 'http://<shop>.myshopify.com',
  apiVersion: '2024-07',
  publicAccessToken: '<access-token>'
});
export const fetchCollectionByHandle = async (handle) => {


  const query = `
    query {
      collectionByHandle(handle: "${handle}") {
        id
        title
        products(first: 10) {
          edges {
            node {
              id
              title
              description
              images(first: 1) {
                edges {
                  node {
                    url
                  }
                }
              }
            }
          }
        }
      }
    }
  `;

  try {

    const response = await client.request(query);

    const products = response.data.collectionByHandle.products.edges;

    if (!products || products.length === 0) {
      throw new Error('No products found in this collection.');
    }

    return products;
  } catch (error) {
    console.error('Error fetching products by collection handle:', error);
    return [];
  }
};

const products = await fetchCollectionByHandle("snowboard");
console.log(products);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants