I can't get metafield data through storefront API

Solved

I can't get metafield data through storefront API

TinWinston
Shopify Partner
3 1 0

I can get metafield data through the restadmin API,The returned results are as follows:

mspurelife_0-1662108485784.png

But I can't get metafield data through storefront API:

 

 $query = <<<QUERY
query {
customer(customerAccessToken: "$token") {
id
createdAt
metafield(namespace: "custom", key: "avtar"){
value
}
firstName
lastName
acceptsMarketing
email
phone
}
}
QUERY;
$resp = $clientFront->query(["query" => $query])->getDecodedBody();

 

The resulting metafield result is null:

 

["data"] => array(1) {
    ["customer"] => array(8) {
      ["id"] => string(48) "Z2lkOi8vc2hvcGlmeS9DdXN0b21lci82MzI1NTI3NjQyMzY4"
      ["createdAt"] => string(20) "2022-09-02T02:39:38Z"
      ["metafield"] => NULL
      ["firstName"] => string(7) "Chunhui"
      ["lastName"] => string(3) "Ren"
      ["acceptsMarketing"] => bool(false)
      ["email"] => string(24) "renchunhui2008@gmail.com"
      ["phone"] => NULL
    }
  }

 

Accepted Solution (1)

TinWinston
Shopify Partner
3 1 0

This is an accepted solution.

If it needs to be selected in the background Expose this metafield to Storefront API requests.
mspurelife_0-1662357444394.png

 

View solution in original post

Reply 1 (1)

TinWinston
Shopify Partner
3 1 0

This is an accepted solution.

If it needs to be selected in the background Expose this metafield to Storefront API requests.
mspurelife_0-1662357444394.png