# Shopify function input query metafield

**URL:** <https://community.shopify.com/t/shopify-function-input-query-metafield/322537>\
**Category:** Functions\
**Tags:** input-queries\
**Created:** [May 14, 2024, 8:32am UTC](https://community.shopify.com/t/shopify-function-input-query-metafield/322537 "2024-05-14T08:32:37Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated 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.

<div class="post-metadata">

**Author:** ![jakehe](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jakehe](https://community.shopify.com/u/jakehe)\
**Post date:** [May 14, 2024, 8:32am UTC](https://community.shopify.com/t/shopify-function-input-query-metafield/322537/1 "2024-05-14T08:32:37Z")

</div>

Hi,

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

 ![Screenshot 2024-05-14 at 6.31.45 PM.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/4/9/497a6ba6922b493e15676731133b79ccd478cd01.png)

Input query is this

```auto
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

```javascript
{
  "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"
          }
        ]
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Hamza\_Hussain](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/hamza_hussain/32/252281_2.png) [@Hamza\_Hussain](https://community.shopify.com/u/Hamza_Hussain)\
**Post date:** [May 14, 2024, 11:53am UTC](https://community.shopify.com/t/shopify-function-input-query-metafield/322537/2 "2024-05-14T11:53:20Z")

</div>

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

 ![Hamza_Hussain_0-1715685646576.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/7/d/7d366893e9006711b68505063c0e12b44583e123.png)

Ask Shopify for the Customer data access

---

<div class="post-metadata">

**Author:** ![jakehe](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jakehe](https://community.shopify.com/u/jakehe)\
**Post date:** [May 14, 2024, 12:22pm UTC](https://community.shopify.com/t/shopify-function-input-query-metafield/322537/3 "2024-05-14T12:22:06Z")

</div>

![Screenshot 2024-05-14 at 10.19.12 PM.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/6/f/6f7cbff0430a8b07180cddb4ef45832eec251e03.png)

`metafield` is still returned as null

Is metafield key and namespace value correct?

Am I using it correctly?

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

```

---

<div class="post-metadata">

**Author:** ![jakehe](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jakehe](https://community.shopify.com/u/jakehe)\
**Post date:** [May 14, 2024, 12:34pm UTC](https://community.shopify.com/t/shopify-function-input-query-metafield/322537/4 "2024-05-14T12:34:21Z")

</div>

I got it working!

key and namspace values were wrong

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

```

---

<div class="post-metadata">

**Author:** ![PrasidKayastha](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/prasidkayastha/32/309744_2.png) [@PrasidKayastha](https://community.shopify.com/u/PrasidKayastha)\
**Post date:** [July 17, 2024, 7:50am UTC](https://community.shopify.com/t/shopify-function-input-query-metafield/322537/5 "2024-07-17T07:50:38Z")

</div>

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

```javascript
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
      } 
    }
  }
}

```
