Development discussions around Shopify APIs
Maybe you can help me write a query in GraphQL.
I want a query so if a product has a media file (glb) I want to make it active. If not, I want it archived. How would I do this? I am thinking a query for all products with GLBs, and another query for all products without GLBs, and use those lists of GIDs to activate or archive respectively. Is there an easier way? How do I check for existence of a media file?
Hey @BeamJokerFavor
You could use the Media connection on the Product to do this - check out the post here for further details and be sure to see the GraphQL reference docs here - thanks!
This requires a gid for a single product. Would I have to loop through all my products one at a time?
Hey @BeamJokerFavor
Yes, it does appear, that you would have to loop through/handle this programatically.
With GQL to do it without a gid would require something more complex like this below. Not necessarily great, but would return the Model 3D GLB.
{
products(first:5){
edges {
node {
title
productType
media(first:5) {
edges {
node {
mediaContentType
__typename
... fieldsForMediaTypes
}
}
}
}
}
}
}
fragment fieldsForMediaTypes on Media {
alt
mediaContentType
status
... on Model3d {
sources {
format
mimeType
url
}
originalSource {
format
mimeType
url
}
}
}
Perhaps filtering via some custom logic on the result of the dataset that is returned from the above could be an option considering your use case.
All this aside, I think this is an excellent piece of feedback - it feels to me like this could be easier honestly - and I've raised this as a feature request with the Product team for their consideration. Hope this helps explain more at least!
User | RANK |
---|---|
49 | |
11 | |
5 | |
5 | |
5 |
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023