How can I retrieve multiple metafields at once from Storefront API GraphQL?

Solved

How can I retrieve multiple metafields at once from Storefront API GraphQL?

yusuke_sasamori
Tourist
12 0 2

Now I want to get multiple matafields from Shopify Storefront API GraphQL at the same time.

I'm trying to get data using the  following GraphQL, but it seems I can't get multiple metafields at the same time.

 

{
  products(first: 10) {
    edges {
      node {
        metafields(identifiers: {namespace: "pre-purchase", key: "*"}) {
          id
        }
      }
    }
  }
}

Because my product has the following data.

namespace: pre-purchase, key: flag, value: 1

namespace: pre-purchase, key: start_at, value: 2022/01/01

namespace: pre-purchase, key: end_at, value: 2023/01/01

How can I get above metafield data at one time??

 

Accepted Solutions (2)

Millerforters
Visitor
1 1 2

This is an accepted solution.

Try this namespace    lcpsgo

 

{
 "product": {
 "metafields": [{
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },
 {
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },

View solution in original post

Viileeu72
Excursionist
12 1 1

This is an accepted solution.

product": {
 "metafields": [{
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },
 {
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },
banned

View solution in original post

Replies 4 (4)

Millerforters
Visitor
1 1 2

This is an accepted solution.

Try this namespace    lcpsgo

 

{
 "product": {
 "metafields": [{
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },
 {
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },
Viileeu72
Excursionist
12 1 1

This is an accepted solution.

product": {
 "metafields": [{
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },
 {
 "namespace": "your_namespace",
 "key": "your_key",
 "value": "your_value",
 "value_type": "string"
 },
banned
yusuke_sasamori
Tourist
12 0 2

I've tried the following query, then problems was solved.

          metafields(identifiers: 
            [
              {namespace: "hogehoge", key: "key"},
              {namespace: "hogehoge", key: "flag"},
              {namespace: "hogehoge", key: "start_at"},
              {namespace: "hogehoge", key: "end_at"}
            ]) {
            value
            key
            namespace
          }

Thank you for your support!

yusuke_sasamori
Tourist
12 0 2

Thanks! It seems problem was solved!!