I’m trying to follow the ‘Getting started with…’ tutorials for Admin Action and Admin Block extensions; and cannot get the GraphQL requests to work - each one of them returns error 400 Bad Request with the response:
{"errors":{"query":"Required parameter missing or invalid"}}
The query is simple and valid, trying to get certain metafields from Products:
export async function getIssues(productId) {
// This example uses metafields to store the data. For more information, refer to https://shopify.dev/docs/apps/custom-data/metafields.
return await makeGraphQLQuery(
`query Product($id: ID!) {
product(id: $id) {
metafield(namespace: "$app:issues", key:"issues") {
value
}
}
}
`,
{ id: productId }
);
}
And the GraphQL call method aligns what I’ve found in other docs:
This leads me to believe that fetch() strips the body from the request – why is that? Is this a known issue? I’ve been searching the forums for a solution, and here someone had a similar problem that was solved by disabling the request body parsing. Is this possible from an Admin extension?
thanks for taking time – yes, it still happens. I’ve tried again from scratch to replicate it, here are my steps:
I wanted to run an admin action, so I followed a tutorial here (which requires me to create an app as shown here)
I’ve named my app, selected an existing Shopify App, and selected one of my stores to preview it on
I’ve installed the app on the store too
I’ve installed the Shopify CLI latest version
I’ve create an extension using the npm run shopify app generate extension ... command
Without even continuing further, I’ve ran npm run dev and previewed my admin action on a real product on my store. Since the template code already has a GraphQL query, I could verify that it doesn’t work; please check out my screenshots:
Which out of the box has a GraphQL call to show you what’s the current product when you open the admin action.
I’ve ran the npm run dev to get to the console, and clicked on the extension to preview it – I’m still facing the same error (see in screenshot that there’s no product name):