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