Development discussions around Shopify APIs
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
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 |
---|---|
5 | |
5 | |
5 | |
5 | |
4 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022