Is it possible to trigger the creation of a smart collection based on a tag or meta field?
Topic summary
-
Main issue: Automate creating a (smart) collection in Shopify based on a tag or metafield using Shopify Flow (automation tool). A metafield is a custom data field on resources like products.
-
Proposed approach: Use Flow’s “Send HTTP Request” action to call the Admin GraphQL API (collectionCreate mutation). Requires setting up/using an API key and configuring the request body/headers correctly.
-
User challenge: Non-developer struggling to pull a specific metafield (cus_sport_or_game) and use its value (e.g., “Yugioh”). Encountered an error: a request header contained CR/LF (carriage return/line feed, i.e., newlines), which is invalid in headers. They don’t need the product ID and want only the clean metafield value.
-
Additional guidance: Before creating a collection, check if it already exists. Suggested using Flow’s “Get collection data” action with a query matching what’s in the metafield (e.g., title) to prevent duplicates.
-
Status/outcome: No concrete solution implemented in-thread. The user is considering hiring a developer due to complexity. Discussion remains open with unresolved configuration details (properly extracting the metafield value and forming valid API requests).
You can use the Send HTTP Request action to call the API.
Here’s one endpoint: https://shopify.dev/docs/api/admin-graphql/2024-01/mutations/collectionCreate
So this is a step in flow that can be created?
You choose the action “Send HTTP Request” and use it to call an API. You need to create or choose an API key in order to do that. If you search the community for Send HTTP Request, you’ll find some examples
This for me is overly complicated. I am not a developer by any means. I
am not sure what to put into the flow fields. I am simply trying to pull
data from a metafield we created, and then look for a collection with that
name and if not one already there create one. I seem to be able to pull
data but not from a specific metafield, and when I do I get this…
header has field value “gid://shopify/Product/9070626373907\n 2022\n\n
Yugioh Joe\n\n The Teen Titans\n\n Yugioh”, this cannot include CR/LF
I don’t really need to pull the ID of the product I don’t think but was
trying to see what it is doing. I simply was trying to pull one field
which is cus_sport_or_game and that should show Yugioh without anything
else.
Please advise if you can.
Well you might not be a developer, but you are developing an application to customize your shop when you build an automation. Often what seems simple turns into something a bit more complicated, like for example you need also check if a collection is already there.
Anyway, to check for a collection based on a metafield value, I think you need to use “Get collection data” as an action with pass in a query with whatever is stored in that metafield. Is it the title ?
Thanks but I am not to the collection checking step as Shopify doesn’t return what I am expecting in some of the previous steps. I will consider hiring a developer.