A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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
}
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
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.
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