GraphQL Customers Metafields and Metafield doesn't work

k-karen
New Member
2 0 0

https://shopify.dev/graphiql/admin-graphiql

I sent the following request in reference to the above page.

 

{
  customers(first: 1, query: "ids:SAMPLE_CUSTOMER_ID") {
    edges {
      node {
        id
        samplekey: metafield(key: "samplekey", namespace: "samplenamespace") {
          value
        }
        metafields(namespace: "samplenamespace", first: 1) {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }

  customer(id: "gid://shopify/Customer/SAMPLE_CUSTOMER_ID") {
    metafield(namespace: "samplenamespace", key: "samplekey") {
      value
    }

    metafields(namespace: "samplenamespace", first: 1) {
      edges {
        node {
          key
          value
        }
      }
    }
  }
}

 

I got following response.

 

{
    "data": {
        "customers": {
            "edges": [
                {
                    "node": {
                        "id": "gid://shopify/Customer/SAMPLE_CUSTOMER_ID",
                        "samplekey": null,
                        "metafields": {
                            "edges": []
                        }
                    }
                }
            ]
        },
        "customer": {
            "metafield": {
                "value": "VALUE1"
            },
            "metafields": {
                "edges": [
                    {
                        "node": {
                            "key": "samplekey",
                            "value": "VALUE1"
                        }
                    }
                ]
            }
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 12,
            "actualQueryCost": 11,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 989,
                "restoreRate": 50.0
            }
        }
    }
}

 


This Customer really has a Metafield.
We checked that with CustomerQuery.
But the CustomersQuery shows that there was no Metafields.

Why? Can't I get the Metafield in CustomersQuery?
Do I need to use CustomerQuery instead of CustomersQuery to get the Customer's Metafield?

0 Likes
k-karen
New Member
2 0 0

Sorry. I solved.

It's caused by my wrong query.

 

customers(first: 1, query: "ids:SAMPLE_CUSTOMER_ID")

 

 

customers(first: 1, query: "id:SAMPLE_CUSTOMER_ID")

 

This query works well.

 

0 Likes