App reviews, troubleshooting, and recommendations
I’m currently facing an issue with accessing multiple metafields inside Shopify discount functions. Using the discountAutomaticAppCreate GraphQL mutation, I created 2 automatic discounts with the same appId and same metafields namespace, resulting in two discounts, each containing metafield data. Each discount has its own metafield data, but the keys are different while sharing the same namespace.
When I try to access a single metafield like this:
discountNode { metafield(namespace: "test", key: "test-key") { value } }
It retrieves the value by specifying the metafield key. However, since the keys are different, I’m struggling to retrieve both metafields within the same namespace.
However, I’m unable to retrieve these metafield values within the Shopify discount functions. Below is the input.graphql code I’ve been working with.
query GetCartContents($selectedCollectionIds: [ID!]) { cart { lines { quantity merchandise { __typename ... on ProductVariant { id product { id inAnyCollection(ids: $selectedCollectionIds) } } } } } discountNode { metafield(namespace: "test", key: "test-key") { value } } }
If anyone has insights or solutions for this, I’d greatly appreciate your help!
Solved! Go to the solution
This is an accepted solution.
You can easily handle this problem by giving an alias to each metafield query:
discountNode {
metafield1: metafield(namespace: "test", key: "test-key-1") {
value
}
metafield2: metafield(namespace: "test", key: "test-key-2") {
value
}
}
Best,
Tobe
This is an accepted solution.
You can easily handle this problem by giving an alias to each metafield query:
discountNode {
metafield1: metafield(namespace: "test", key: "test-key-1") {
value
}
metafield2: metafield(namespace: "test", key: "test-key-2") {
value
}
}
Best,
Tobe
Hi Tobe,
Thanks for your reply, really appreciate it.
I’ve tried the same approach, but it’s not working as expected. It does return a metafield value, but not both. Sometimes it returns the value of metafield1, and sometimes it returns metafield2.
Here's the output:
"discountNode": {
"metafield1": null,
"metafield2": {
"value": "{\"title\":"Test metadata",\"products\":[]}"
},
},
and here's the input.graphql file code
query GetCartContents($selectedCollectionIds: [ID!]) {
cart {
lines {
quantity
merchandise {
__typename
... on ProductVariant {
id
product {
id
inAnyCollection(ids: $selectedCollectionIds)
}
}
}
}
}
discountNode {
metafield1: metafield(namespace: "test", key: "test-key") {
value
}
metafield2: metafield(namespace: "test", key: "test-key-1") {
value
}
}
}
Let me know if I’m doing anything wrong.
Thanks
Dinesh
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024