Null Metafields with customer account api

Hi All,

I have a small problem with my graphql query hitting the customer-account api from within a customer ui extension. I am trying to get some customer metafields along with some other customer information and I keep getting a null back instead.

Here is my query:

const getCustomerQuery = {
    query: `query{
      customer{
        id
        lastName
        firstName
        metafields(identifiers:[{key:"mandate_accepted",namespace:"abilita"},{namespace:"abilita",key:"mandate_info"},{namespace:"abilita",key:"iban"}]){
          value
          key
        }
      }
    }`
  }

I get the following back:

{
    "data": {
        "customer": {
            "id": "gid://shopify/Customer/8415572001044",
            "lastName": "Gilbert",
            "firstName": "Gary",
            "metafields": [
                null,
                null,
                null
            ]
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 2,
            "actualQueryCost": 2,
            "throttleStatus": {
                "maximumAvailable": 7500.0,
                "currentlyAvailable": 7498,
                "restoreRate": 100.0
            }
        }
    }
}

Now when I use graphiql from the terminal (same access scopes as the app) and reformat the query for graphiql

 query{
  customer(id:"gid://shopify/Customer/8415572001044"){
    firstName
    id
    lastName
    metafields(first:3 namespace:"abilita"){
      nodes{
        key
        value
        type
      }
    }
  }
}

I get the expected results

{
  "data": {
    "customer": {
      "firstName": "Gary",
      "id": "gid://shopify/Customer/8415572001044",
      "lastName": "Gilbert",
      "metafields": {
        "nodes": [
          {
            "key": "mandate_accepted",
            "value": "false",
            "type": "boolean"
          },
          {
            "key": "mandate_info",
            "value": "{}",
            "type": "json"
          },
          {
            "key": "iban",
            "value": "12345",
            "type": "single_line_text_field"
          }
        ]
      }
    }
  },

Anybody know or have an idea why Im getting back nulls? @Liam-Shopify got an idea? :slight_smile:

Cheers and thanks!
Gary

Hey Gary! Could you try running the query again and include the errors field? Curious to see what that returns

Hi Anahita,

No errors, otherwise I wouldn’t have gotten a result. Generally if there is a user error or a malformed query the data is null or not even existent and then you get only the errors array back.

But I ran it again anyway. The full response from the API is what I pasted in the original post.

{
    "data": {
        "customer": {
            "id": "gid://shopify/Customer/8415572001044",
            "lastName": "Gilbert",
            "firstName": "Gary",
            "metafields": [
                null,
                null,
                null
            ]
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 2,
            "actualQueryCost": 2,
            "throttleStatus": {
                "maximumAvailable": 7500.0,
                "currentlyAvailable": 7498,
                "restoreRate": 100.0
            }
        }
    }
}

Hallo @Anahita_Mohapatra,

I have a Shopify request id so that you can see why the metafields came back null.

x-request-id: 9b19a961-7592-44fb-8eff-df4a58db70f8-1732983005

I would appreciate some feedback on this as I need to. be able to access the metafields.

Cheers,
Gary

Hi, I did a quick check and it doesn’t appear that your metafields have sufficient access via the Customer Account API.

As a note, if you’re running GraphiQL via the dev console, this is running queries against the Admin API which has a different access control from a metafield standpoint.

You can take a look here for updating access via the Admin API, or you can change the access level via the Admin UI by navigating to the metafield definition under settings and updating the “Customer account access” dropdown.

1 Like

Hi JR

Well :poop: !

That was the one thing I didnt think about. I thought the access was done strictly through the access scopes and not through the additional requirement of creating the metafield definition to allow access to the customer api.

Switching that in the definition via the admin to allow access worked. I am now getting the values and keys instead of just nulls.

Cheers and Thanks!

Gary

1 Like