Hi, I can’t get products using Graphql (I’m always getting a 404), but I can get them using the REST API.
I have tested the query in Shopify’s Graphql explorer. I really don’t know what else I can do.
Thanks in advance.
This is my code:
getProductsUsingRest method (works properly)
const baseUrl = `https://${config.SHOPIFY_STORE_NAME}.myshopify.com/admin/api/2023-01`
export const getProductsUsingRest = async () => {
const headers = {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': config.SHOPIFY_ACCESS_TOKEN,
}
const url = `${baseUrl}/products.json`
const res = await axios.get(url, { headers });
return res.data;
}
getProductsUsingGraphql method (always returns a 404)
const baseUrl = `https://${config.SHOPIFY_STORE_NAME}.myshopify.com/admin/api/2023-01`
export const getProductsUsingGraphql = async () => {
const headers = {
'Content-Type': 'application/graphql',
'X-Shopify-Access-Token': config.SHOPIFY_ACCESS_TOKEN,
}
const url = `${baseUrl}/graphql.json`
const query = `
{
products(first: 3) {
edges {
node {
id,
title
}
}
}
}`
const res = await axios.post(url, query, {headers});
return res.data;
}