Discussing Shopify Functions development, deployment, and usage in Shopify apps.
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"
}
]
}
]
}
}
Solved! Go to the solution
This is an accepted solution.
I got it working!
key and namspace values were wrong
metafield (key:"locality", namespace:"custom"){
value
}
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
}
This is an accepted solution.
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
}
}
}
}