Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
How to update this part of the code to extract metafields values correctly? Or what to paste to the edit query instead?
{
"query": {
"objectType": "product",
"id": "product.id",
"metafields": [
{
"namespace": "my_fields",
"key": "style1"
},
{
"namespace": "my_fields",
"key": "year"
},
{
"namespace": "my_fields",
"key": "season1"
},
{
"namespace": "my_fields",
"key": "special"
},
{
"namespace": "my_fields",
"key": "waist"
},
{
"namespace": "my_fields",
"key": "closure"
}
]
}
}
Solved! Go to the solution
This is an accepted solution.
This gets the metafield by namespace/key and outputs the value. "first" is needed because "where" returns a list.
{%- assign mf_object = product.metafields | where: "namespace", "my_fields" | where: "key", "pattern" | first -%}
{{ mf_object.value }}
Look at the example queries and the search syntax. You don't need to build the whole query ... just the query string
To add... Shopify's product query does not allow searching by metafields yet. https://shopify.dev/docs/api/admin-graphql/2023-07/queries/products#argument-products-query
What are you trying to do in your workflow?
Pass data from metafields to Open AI for text generation.
Yes, but hot to take a date from Metafields? I don't need all of them.
You might not need a query for this. When should the workflow run? Once you have a product in the workflow, you can access all of it's metafields in liquid directly in the OpenAI action
See https://community.shopify.com/c/shopify-flow-app/how-to-use-shopify-flow-to-pick-up-color-names-from... for some code
I know, but how to filter them out? Because they look like this:
I'm not sure where / how you want to filter them out. If you mean access a single value in liquid, my preferred approach is like this:
{%- assign mf_object = product.metafields | where: "namespace", "custom" | where: "key", "color" | first -%}
If you mean in a condition, here's example example for order metafields:
Things are more complex in my case. I am already checking if the required values are in the product:
Then I need to pass exact metafields variables to the Ai prompt here, not just one specific value, to generate a product description based on different parameters Metafield1, Metafield2, Metafield3, and so on:
Each metafield can have many variations, not just one:
I'm not sure what you mean by "variables". I think, b/c of that screenshot, you want all of the possible values for the metafield in that Open AI prompt? That isn't a metafield value, but I think a metafield definition. I think the choices are stored in validations. You might need to use GraphiQL or a GraphQL client to find the right key name to use for that. Also, you may run into an API limit as query metafields this way is very costly.
Variables are metafields: like the one I show on the print screen, how do I add "product.metafields.my_fields.pattern" to the place Metafield1, as I show on the print screen?
What exact piece of code do I have to add to that place?
This is an accepted solution.
This gets the metafield by namespace/key and outputs the value. "first" is needed because "where" returns a list.
{%- assign mf_object = product.metafields | where: "namespace", "my_fields" | where: "key", "pattern" | first -%}
{{ mf_object.value }}
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024