Has anyone done a query for Articles that have metafields?
I can query the articles with its title, otherfields etc,
but by default Shopify won’t return the articles metafields in this call. These metafields for these articles have been created by an app. My first goal would be trying to call all articles and view its metafields also.
Currently…
# My Graphql
{
articles(first:2){
edges{
node{
title
excerpt
}
}
}
}
# Json Response
{
"data": {
"articles": {
"edges": [
{
"node": {
"title": "First Post",
"excerpt": ""
}
},
{
"node": {
"title": "Second Post",
"excerpt": ""
}
}
]
}
}
}
What I hope for …
My Graphql:
{
articles(first:2){
edges{
node{
title
excerpt
metafields
}
}
}
}
# Response
{
"data": {
"articles": {
"edges": [
{
"node": {
"title": "First Post",
"excerpt": "",
"metafields":[{
"namespace":"mynamespacehere",
"key":"mykey",
"value":"Some Value"
}
]
}
}
##...all other posts
]
}
}
}
2 Answers
Works exactly like described here:
https://shopify.dev/docs/admin-api/graphql/reference/metafields/metafield
if you want to query a certain meta field
its
fieldName: metafield(namespace: "YOUR_NAMESPACE", key: "YOUR_KEY"){
value
}
As of Nov 2020 it seems like metafield queries only work against the ADMIN GraphQL API. When I try them with the Storefront API it returns null for everything I query.
PS: Seems like you have to enable each metafield you want to access via Storefront:
https://shopify.dev/tutorials/retrieve-metafields-with-storefront-api
I am confused over namespace and key . can someone guide me with example
1
-
abdul Hadi, this does not provide an answer to the question. You can search for similar questions, or refer to the related and linked questions on the right-hand side of the page to find an answer. If you have a related but different question, ask a new question, and include a link to this one to help provide context. See: Ask questions, get answers, no distractions
– Yunnosch29 mins ago