A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello! I am building a shopify app that can pull a connected store's analytics and reports data. I have set up the request and fetch functions with my remix app.
Currently, I am getting this response in my app frontend when I preview in my browser from the query:
{
"data": {
"shopifyqlQuery": {
"tableData": {
"unformattedData": [],
"rowData": [],
"columns": [
{
"name": "month",
"dataType": "month",
"displayName": "Month"
},
{
"name": "monthly_net_sales",
"dataType": "price",
"displayName": "Monthly net sales"
}
]
}
}
},
"extensions": {
"cost": {
"requestedQueryCost": 3,
"actualQueryCost": 3,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 997,
"restoreRate": 50
}
}
}
}
I believe I am getting this response because my test dev store does not have any dummy analytics, but there are sample reports with information.
Here is a snippet of my code in my app_index.jsx:
export const loader = async ({ request }) => {
const { admin } = await authenticate.admin(request);
const reportsData = await fetchShopifyReports(admin);
return json({ reports: reportsData });
};
export const action = async ({ request }) => {
const { admin } = await authenticate.admin(request);
const color = ["Red", "Orange", "Yellow", "Green"][
Math.floor(Math.random() * 4)
];
const response = await admin.graphql(
`#graphql
mutation populateProduct($input: ProductInput!) {
productCreate(input: $input) {
product {
id
title
handle
status
variants(first: 10) {
edges {
node {
id
price
barcode
createdAt
}
}
}
}
}
}`,
{
variables: {
input: {
title: `${color} Snowboard`,
variants: [{ price: Math.random() * 100 }],
},
},
}
);
const responseJson = await response.json();
return json({
product: responseJson.data.productCreate.product,
});
};
export default function Index() {
const nav = useNavigation();
const actionData = useActionData();
const { reports } = useLoaderData(); // Retrieve reports from loader
const submit = useSubmit();
const isLoading =
["loading", "submitting"].includes(nav.state) && nav.formMethod === "POST";
const productId = actionData?.product?.id.replace(
"gid://shopify/Product/",
""
);
My question is how can I properly query to pull all data from analytics holistically, and properly display that information on the frontend.
Note: i am a novice engineer! Learning as I build, any guidance and constructive advice for next steps is greatly appreciated. Also happy to provide more code for context if needed.
Thanks! 😁
Solved! Go to the solution
This is an accepted solution.
When you say "my test dev store does not have any dummy analytics, but there are sample reports with information" - how are these sample reports set up? It's possible the query is correct and there's simply no valid data to receive?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me 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
Hi Mike,
Just to confirm - are you expecting to see some traffic data being returned in the first code snippet, but there's missing data?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me 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
Hi Liam, yes correct! This was my attempt to just get the API communication working, but wondering if there is a better method than what I'm doing to pull a merchant's total analytics/report data, rather than specified fields. Any clarification on how this can work better with what I'm attempting would be super helpful 🙂
Edit: For more clarification, if it is easier to capture orders, traffic sessions, and checkout conversion outside of the reports query -- that would also work too. My goal is to get this data and send to the openAI API for cross-analysis.
This is an accepted solution.
When you say "my test dev store does not have any dummy analytics, but there are sample reports with information" - how are these sample reports set up? It's possible the query is correct and there's simply no valid data to receive?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me 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
Hey! This seems to be the case, and since then I have tried pulling different data such as orders and abandoned carts, but running into a TypeError issue with the REST client in remix. I have made a new post in the proper forum category (i hope), linking here if you have any advice for this issue.