A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi @AlexWebLab 👋
After the `stagedUploadsCreate` mutation, the video will have to be uploaded to the target. Keep in mind that for videos, this should be a POST request to the `stagedTarget.url` in a multipart form including all parameters from `stagedTarget.parameters` field in preserved order.
Once the video has been successfully uploaded to the target, the `productCreateMedia` mutation can consume the `stagedTarget.resourceUrl`. I'd recommend reviewing this guide to manage media for products as well.
Here is an implementation using pre/post-request scripts with the Postman client, and similar logic can be applied in your app's native language.
// post stagedUploadsCreate request
const r = pm.response.json(); //response from stagedUploadsCreate mutation
const target = r.data.stagedUploadsCreate.stagedTargets[0]
pm.collectionVariables.set("target-url", target.url);
pm.collectionVariables.set("target-params", target.parameters);
pm.collectionVariables.set(
"target-resource-url",
JSON.stringify(target.resourceUrl)
);
// pre video upload request
const params = Array.from(pm.collectionVariables.get("target-params"));
params.reverse().forEach( p => {
pm.request.body.formdata.prepend({
key: p.name,
value: p.value
})
})
Hope that helps!
Umiko | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hello Umiko,
Thank you for your time.
Your suggestion helps and it works if I'm uploading the video from my computer.
What I'm trying to achieve here is to copy media from a product of one store to a product of another store.
In this guide: Manage media for products it's stated that IF the asset is hosted by Shopify, THEN I can skip the "stagedUploadsCreate" mutation. And actually, I can do that with the IMAGE media type but not with the VIDEO media type. That's the problem.
It's unclear if I can also migrate VIDEOS other than IMAGES without the need of downloading them first on my computer.
Thanks for your help!
Hey AlexWebLab_
I am facing a similar problem: receving "Invalid video url" error on trying to use the "ProductCreateMedia" GraphQL mutation with a shopify hosted video.
Using my current workflow I can upload an "EXTERNAL_VIDEO" video type, so my query and CURL functions are working.
I wondered if you found a solution to your problem, in the mean time Ill keep looking 😉
Thanks for your time and cheers,
Matthias
Hi @Matthias 👋
When using the `productCreateMedia` mutation, the `CreateMediaInput.originalSource` field should be an external URL or a staged upload URL. This means that if you pass a Shopify CDN hosted URL, it will not be accepted an "external URL" and expects the staged upload URL instead.
Since videos hosted on one Shopify store with a Shopify CDN URLs, are not meant to be used to create product media on other Shopify stores, it will likely need to be downloaded and restaged in the new store.
Hope that helps!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi @ShopifyDevSup ,
Thank you very much for your reply.
Ok, that would be the problem.
Cheers,
Matthias
Hi @ShopifyDevSup,
How can I reuse the same VIDEO from an existing product to create a new product in the "same" store? It doesn't make sense to download, restage and upload the video again since the VIDEO is on the same store right? Can we do this using the Files and Media API, so that the same media can be used in different products?