Shopify function input query metafield

Topic summary

A developer is building a custom Shopify delivery function and needs to retrieve customer metafield values through input queries.

Initial Problem:

  • The metafield query was returning null despite proper syntax
  • Query attempted to access customer metafield with key "custom.locality" and namespace "customer"

Solution Found:

  • The issue was incorrect key and namespace values
  • Correct syntax: metafield(key: "locality", namespace: "custom") (without the “custom.” prefix in the key)
  • Required scope: read_customers to access customer data
  • May also need to request “Customer protected data” access through Partner Dashboard → Apps → Your App → API Access

Related Follow-up:
Another developer asked about retrieving multiple metafields for product variants in input queries, specifically for delivery customization features (delivery dates, hospital addresses, product restrictions). This question remains unanswered.

Summarized with AI on November 7. AI used: claude-sonnet-4-5-20250929.

Hi,

I am working on the custom delivery function. How can I get the customer metafield value ?

Input query is this

query RunInput {
  cart {
    buyerIdentity {
      customer {
        id
        displayName
        email
        hasTags ( tags: ["Local pick up"]) {
          hasTag
          tag
        }
        metafield (key:"custom.locality", namespace:"customer"){
          value
        }
      }
    }
    deliveryGroups {
      deliveryAddress {
        provinceCode
      }
      deliveryOptions {
        handle
        title
      }
    }
  }
}

This is the input

{
  "cart": {
    "buyerIdentity": {
      "customer": {
        "id": "gid://shopify/Customer/11111",
        "displayName": "Bob James",
        "email": "a+bob@gmail.com",
        "hasTags": [
          {
            "hasTag": true,
            "tag": "Local pick up"
          }
        ],
        "metafield": null
      }
    },
    "deliveryGroups": [
      {
        "deliveryAddress": {
          "provinceCode": "NSW"
        },
        "deliveryOptions": [
          {
            "handle": "9d6c322a5e8380801094fd4f5cb7293c-5f3137c82b95cc9a5ea6147c93eeed84",
            "title": "Local pick up"
          },
          {
            "handle": "9d6c322a5e8380801094fd4f5cb7293c-c7128c168fccb401d715c207404eee05",
            "title": "Standard"
          }
        ]
      }
    ]
  }
}

Make sure you have the following scope read_customers to access customer data and if that doesn’t work It might be because your app doesn’t have access to customer protected data. If that’s the case then go to Partner Dashboard > Apps > Your App > API Access then scroll to access like in the image below

Ask Shopify for the Customer data access

metafield is still returned as null

Is metafield key and namespace value correct?

Am I using it correctly?

metafield (key:"custom.locality", namespace:"customer"){
          value
        }

I got it working!

key and namspace values were wrong

metafield (key:"locality", namespace:"custom"){
  value
}

Hi Jakehe

I am trying to get multiple metafields value of product variants on input.graphql. How can I achieve that? Could you please help?
run.graphql

query RunInput{
 cart {
    calenderDate: attribute(key: "Delivery-Date") {
      value
    }
    storeTime: attribute(key: "storeDatetime") {
      value
    }
    hospital: attribute(key: "Hospital Address") {
      value
    }
    lines {
      merchandise {
        __typename
        ... on ProductVariant {
          id
          semiAdhoc: metafield(namespace: "custom_fields", key: "semi_adhoc") {
              value
            }
            restrict: metafield(namespace: "custom_fields", key: "region_restrict") {
              value
            }
          product {
            hasTags(
              tags: [
                "adhoc_service_only"
                "hat_box"
                "native_flowers"
                "flower_bouquet"
                "big_rose_bouquet"
                "wildflowers"
                "driedflowers"
                "sydsdhampers"
              ]
            ) {
              hasTag
              tag
            }
          }
        }
      }
    }
    deliveryGroups {
      deliveryAddress {
        provinceCode
        zip
      }
      deliveryOptions {
        handle
        title
        deliveryMethodType
      } 
    }
  }
}