Shopify function input query metafield

Solved

Shopify function input query metafield

jakehe
Shopify Partner
12 1 7

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

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"
          }
        ]
      }
    ]
  }
}

 

Accepted Solution (1)
jakehe
Shopify Partner
12 1 7

This is an accepted solution.

I got it working!

 

key and namspace values were wrong

 

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

View solution in original post

Replies 4 (4)

Hamza_Hussain
Shopify Partner
56 6 13

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

 

Ask Shopify for the Customer data access

Honey G Hamza
jakehe
Shopify Partner
12 1 7

Screenshot 2024-05-14 at 10.19.12 PM.png

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

 

jakehe
Shopify Partner
12 1 7

This is an accepted solution.

I got it working!

 

key and namspace values were wrong

 

metafield (key:"locality", namespace:"custom"){
value
}
PrasidKayastha
Shopify Partner
4 0 5

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