Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Change from accessing Ngrok domain name to [shopname].myshopify.com

Change from accessing Ngrok domain name to [shopname].myshopify.com

nmywrld
Shopify Partner
4 0 2

currently I am trying to make graphQL queries to this endpoint https://{store_name}.myshopify.com/admin/api/2023-01/graphql.json. However, when using the default methods in the nodeJS template, it makes calls to an ngrok tunnel instead; https://c692-122-11-212-**.ap.ngrok.io/admin/api/2023-01/graphql 

 

Other than making sure i have attempted to request for access to protected customer data and the right access scopes: "read_reports, read_customers, read_fulfillments, read_inventory, read_orders, read_products, read_all_orders", what else will i need to make sure i can make valid shopifyQL queries through Graphql? Do i really need to access the store name domain when developing on a development store or is the ngrok tunnel ok?

 

Here are the relevant code

 

// [page name].jsx
  const handleAnalytics = async () => {
    setIsLoading(true);
    const response = await fetch("/admin/api/2023-01/graphql", {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlenconded',
        Accept : 'application/json'
      }
    });
    setIsLoading(false);
    console.log(await response)

 

 

// file name: index.js
app.post("/admin/api/2023-01/graphql", async (_req, res) => {

  const data = await fetchAnalytics(res.locals.shopify.session);  

  res.status(200).send({data})
});
// Helper function
const analytics_query = `query{
    shopifyqlQuery(query: "FROM orders SHOW sum(net_sales)") {
      __typename
      ... on TableResponse {
        tableData {
          unformattedData
          rowData
          columns {
            name
            dataType
            displayName
          }
        }
      }
      parseErrors {
        code
        message
        range {
          start {
            line
            character
          }
          end {
            line
            character
          }
        }
      }
    }
  }`

export default async function fetchAnalytics (session) {
  const client = new shopify.api.clients.Graphql({session});
  res = await client.query({
    data: {
      query: analytics_query
    }
  });
  return res
  }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 238 525

Hi @nmywrld . We think the following workshop guide might have the solution you are looking for in it. You can find it here. The example code 

app.get("/api/shopifyql/sales", async (req, res) => {
  const session = await Shopify.Utils.loadCurrentSession(
    req,
    res,
    app.get("use-online-tokens")
  );

  const client = new Shopify.Clients.Graphql(
    session.shop,
    session.accessToken
  );

  const salesData = await client.query({ // <-------this piece would make the gql request
    data: {
      query: SALES_QUERY
    },
  });

, might be relevant to your situation in this case. Hope this helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

nmywrld
Shopify Partner
4 0 2

Hello. I was under the understanding that in V6, the shopify.utils methods are no longer used ? 

i have used this piece of code in a v5 template and it still queries to the ngrok tunnel rather than the shop domain still. 

ShopifyDevSup
Shopify Staff
1453 238 525

If you're still running into issues, it may be worthwhile to post your issue in the shopify-api-js public repo directly.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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