How to get the URL of an uploaded VIDEO?

Solved

How to get the URL of an uploaded VIDEO?

friendoftheroot
Shopify Partner
48 5 8

On an IMAGE media resource I am successful with staging an upload, curl upload an image and get the url of newly uploaded via:

 

 

					$graphqlstring = '{
						  files (first: 1, query:"filename:'.$arrMedia[0].'") {
							edges {
							  node {
								... on MediaImage {
								  image {
									id
									url
									altText
									height
									width
								  }
								}
							  }
							}
						  }
						}
					';	

 


I get ID and URL in the response which is great.

On an VIDEO resource I am having problems. I am again successful with staging an upload, curl upload the VIDEO but I cannot get the url via (from https://shopify.dev/api/admin-graphql/2022-10/queries/files)

 

 

 

					$graphqlstring = '{
						  files (first: 1, query:"filename:'.$arrMedia[0].'") {
							edges {
							  node {
								... on Video {
								  id
								  duration
								  preview {
									status
									image {
									  id
									  width
									  height
									  url
									}
								  }
								  originalSource {
									url
									width
									height
									format
									mimeType
								  }
								  sources {
									url
									width
									height
									format
									mimeType
								  }
								}
							  }
							}
						  }
						}
					';						

 

 

 

I had to omit "originalFileSize" from the documentation because that threw an error (not available).

I only get this result still missing the url:

 

 

[data] => Array
        (
            [files] => Array
                (
                    [edges] => Array
                        (
                            [0] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/28012370f1795
                                            [duration] => 
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )

                                            [originalSource] => 
                                            [sources] => Array
                                                (
                                                )

                                        )

                                )

                        )

                )

        )

 


Any hints how to get the URL, or how to proceed from here?

Thank you.

Accepted Solution (1)
friendoftheroot
Shopify Partner
48 5 8

This is an accepted solution.

@Alan  hey, thanks for the input.

My app was not the culprit as I use low level code that gives me raw results similar to postman. But I found the problem in the query to retrieve the filename. 

As always I try to make my feedback elaborate enough for the next developer on this forum struggling with the same problem.

Suggestions from you and tutorials where to use:

 

{
					  files(first: 1, reverse:true) {
						edges {
						  node {
							... on Video {
							  id
							  duration
							  preview {
								status
								image {
								  id
								  width
								  height
								  url
								}
							  }
							  originalSource {
								url
								width
								height
								format
								mimeType
							  }
							  sources {
								url
								width
								height
								format
								mimeType
							  }
							}
						  }
						}
					  }
					}

 

 

 

This results in what I posted above: [status] => UPLOADED but no src for the video file in different resolutions:

 

 

 

    [data] => Array
        (
            [files] => Array
                (
                    [edges] => Array
                        (
                            [0] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/283368716xxxxx
                                            [duration] => 
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )

                                            [originalSource] => 
                                            [sources] => Array
                                                (
                                                )

                                        )

                                )

                        )

                )

        )

 

 

 



Now, when I do this instead: ***

 

 

{
					  files(first: 2, reverse:true) {
						edges {
						  node {
							... on Video {
							  id
							  filename
							  duration
and so on..

 

 

The result is where all the data resides. 🙂
Adding the filename to the query helped me to identify that the file was the same that I uploaded.

 

 

Array
(
    [data] => Array
        (
            [files] => Array
                (
                    [edges] => Array
                        (
                            [0] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/28368019161xxx
                                            [duration] => 
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )

                                            [originalSource] => 
                                            [sources] => Array
                                                (
                                                )

                                        )

                                )

                            [1] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/28367999467yyy
                                            [duration] => 11120
                                            [preview] => Array
                                                (
                                                    [status] => READY
                                                    [image] => Array
                                                        (
                                                            [id] => gid://shopify/ImageSource/28383785451xxx
                                                            [width] => 1080
                                                            [height] => 1300
                                                            [url] => https://cdn.shopify.com/s/files/1/0620/5312/2211/files/preview_images/6a983a94ab784a4e97bf68c9954xxxx.thumbnail.0000000000.jpg?v=1666639534
                                                        )

                                                )

                                            [originalSource] => Array
                                                (
                                                    [url] => https://cdn.shopify.com/videos/c/o/v/6a983a94ab784a4e97bf68c9954xxxx.mp4
                                                    [width] => 1080
                                                    [height] => 1300
                                                    [format] => mp4
                                                    [mimeType] => video/mp4
                                                )

                                            [sources] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.HD-1080p-7.2Mbps-10106389.mp4
                                                            [width] => 896
                                                            [height] => 1080
                                                            [format] => mp4
                                                            [mimeType] => video/mp4
                                                        )

                                                    [1] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.m3u8
                                                            [width] => 896
                                                            [height] => 1080
                                                            [format] => m3u8
                                                            [mimeType] => application/x-mpegURL
                                                        )

                                                    [2] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.HD-720p-4.5Mbps-10106389.mp4
                                                            [width] => 598
                                                            [height] => 720
                                                            [format] => mp4
                                                            [mimeType] => video/mp4
                                                        )

                                                    [3] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.SD-480p-1.5Mbps-10106389.mp4
                                                            [width] => 398
                                                            [height] => 480
                                                            [format] => mp4
                                                            [mimeType] => video/mp4
                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [extensions] => Array
        (
            [cost] => Array
                (
                    [requestedQueryCost] => 12
                    [actualQueryCost] => 12
                    [throttleStatus] => Array
                        (
                            [maximumAvailable] => 1000
                            [currentlyAvailable] => 988
                            [restoreRate] => 50
                        )

                )

        )

)
Array
(
    [0] => gid://shopify/Video/28367999467yyy
)

 

 


I also tried to filter for the filename:

 

 

 

$graphqlstring = '{
		 files (first: 2, query:"filename:xyz.mp4") {
and so on..

 

 

 

With this one the same problem comes up, I would expect more useful results there:

 

 

....
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )
and so on..
                               

 

 

 

So I will not filter the filename but instead parse the output of the query marked with *** and compare to the original filename to make sure I get the right one.

 

View solution in original post

Replies 10 (10)

Alan
Shopify Staff
129 15 24

Hey @friendoftheroot - it is odd that you aren't seeing the url surface for the videos. I was able to test the query in my own development environment and couldn't replicate the issue. The urls showed up as expected. 

 

Could you try the original query, but omit the filename parameter after uploading a new video file and seeing if it returns the URL values for the most recent file? I'd recommend a query like this:

{
  files(first: 1, reverse:true) {
    edges {
      node {
        ... on Video {
          id
          duration
          preview {
            status
            image {
              id
              width
              height
              url
            }
          }
          originalSource {
            url
            width
            height
            format
            mimeType
          }
          sources {
            url
            width
            height
            format
            mimeType
          }
        }
      }
    }
  }
}

"filename" is a supported search parameter, but I did want to confirm that the URLs are not being returned at all for the uploaded video. 

 

If you're still seeing the issue, could you share an X-Request-ID from the headers of the most recent response from us? We can look into it further from there. 

 

Hope this helps provide some next steps. 

Alan | 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

friendoftheroot
Shopify Partner
48 5 8

Thank you I appreciate your support. 😃

I tried it again and have the same result. 

Here more details:
[mime] => video/mp4
[postname] => 23340_video_7776051060.mp4

Here are all 3 requests (excluding the curl upload) that I use to get the video online:

This is the x-request-id to reserve the resource:
x-request-id: c682f83d-ba66-4490-ba70-e87c5fb058b1
This is the x-request-id of FileCreate:
x-request-id: 9d5e75e8-3a05-4cf8-9bc5-8367f8c10759
This is the x-request-id to get the video url (using your template above):
x-request-id: 4d9f67c6-eedf-4413-bf76-c592b2e9a6d4

friendoftheroot
Shopify Partner
48 5 8

Hey Alan, I followed up with additional details. Let me send this reply so you get a notification. Cheers

friendoftheroot
Shopify Partner
48 5 8

@Alan Hello Alan, can you take a look into this please. I would appreciate it a lot as I am still stuck here. Thank you so much.

Alan
Shopify Staff
129 15 24

Hey @friendoftheroot - thanks for getting back in touch and for your patience here. I just wanted to mention that we can't guarantee responses through our forums as my team's (API Support) community monitoring tasks do rotate regularly. That said, I'm happy to help as best as I can here.

Our retention logs don't go back far enough on my end for those X-Request-IDs, could you share a more recent example Request ID related to the error? I'll take a look as soon as possible and prioritize a response for you (Monday EST at the latest) since I do realize it has been a while since we first touched base. Hope to hear from you soon - thanks again for your patience. 

Alan | 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

friendoftheroot
Shopify Partner
48 5 8

@Alan Thanks for getting back. I understand the community support is pro bono of sorts. So I appreciate your time.

Here are all 3 requests (excluding the curl upload) that I use to get the video online:

This is the x-request-id to reserve the resource:
x-request-id: d9be4a93-3001-45c8-a2c0-bd13007eda39

This is the x-request-id of FileCreate:
x-request-id: a0315a74-8bd8-4eea-bf00-60a45d134dc1

This is the x-request-id to get the video url and gid (using your template above):
x-request-id: 46c418c9-3fea-4635-81ca-0fce1180ef8c

Manuals and tutorials indicated that there should be a resulting URL, but the request returns this:

    [data] => Array
        (
            [files] => Array
                (
                    [edges] => Array
                        (
                            [0] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/283368716xxxxx
                                            [duration] => 
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )

                                            [originalSource] => 
                                            [sources] => Array
                                                (
                                                )

                                        )

                                )

                        )

                )

        )

 

Alan
Shopify Staff
129 15 24

Hey @friendoftheroot - no worries, thank you for understanding. I've done a bit more looking into this on my end with the help of your X-Request-IDs, so thanks for sending those my way too. Based on what I can see in our logs, the syntax was correct in those queries, so no problems there. It does appear that the URLs for the video in different resolutions were generated as well.

What I'd recommend trying is using your app's authorization credentials in an API client application like Postman or Insomnia and seeing if the data populates as expected there if you haven't already. It's possible that the way your app retrieve's the data after it's been sent your way via JSON on our end isn't being read/picked up properly. If we can confirm the data is retrievable by Postman or another API client app, this usually indicates there's an issue with an app rather than our API. 

I'm unable to provide coding-specific advice, but if you're just using one of our libraries for your app to retrieve API calls without adjustments, I may be able to help a little bit further. 

 

That said, if the issue persists in an API client app or if you're using one of our libraries, could you reach out through our "Report an Issue" form (reached through the "Contact Support" menu in your Partner Dashboard)? We may need to discuss some more sensitive store-level information that we can't share in a public forum to get this further looked into. 

 

Hope this helps! 

Alan | 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

friendoftheroot
Shopify Partner
48 5 8

This is an accepted solution.

@Alan  hey, thanks for the input.

My app was not the culprit as I use low level code that gives me raw results similar to postman. But I found the problem in the query to retrieve the filename. 

As always I try to make my feedback elaborate enough for the next developer on this forum struggling with the same problem.

Suggestions from you and tutorials where to use:

 

{
					  files(first: 1, reverse:true) {
						edges {
						  node {
							... on Video {
							  id
							  duration
							  preview {
								status
								image {
								  id
								  width
								  height
								  url
								}
							  }
							  originalSource {
								url
								width
								height
								format
								mimeType
							  }
							  sources {
								url
								width
								height
								format
								mimeType
							  }
							}
						  }
						}
					  }
					}

 

 

 

This results in what I posted above: [status] => UPLOADED but no src for the video file in different resolutions:

 

 

 

    [data] => Array
        (
            [files] => Array
                (
                    [edges] => Array
                        (
                            [0] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/283368716xxxxx
                                            [duration] => 
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )

                                            [originalSource] => 
                                            [sources] => Array
                                                (
                                                )

                                        )

                                )

                        )

                )

        )

 

 

 



Now, when I do this instead: ***

 

 

{
					  files(first: 2, reverse:true) {
						edges {
						  node {
							... on Video {
							  id
							  filename
							  duration
and so on..

 

 

The result is where all the data resides. 🙂
Adding the filename to the query helped me to identify that the file was the same that I uploaded.

 

 

Array
(
    [data] => Array
        (
            [files] => Array
                (
                    [edges] => Array
                        (
                            [0] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/28368019161xxx
                                            [duration] => 
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )

                                            [originalSource] => 
                                            [sources] => Array
                                                (
                                                )

                                        )

                                )

                            [1] => Array
                                (
                                    [node] => Array
                                        (
                                            [id] => gid://shopify/Video/28367999467yyy
                                            [duration] => 11120
                                            [preview] => Array
                                                (
                                                    [status] => READY
                                                    [image] => Array
                                                        (
                                                            [id] => gid://shopify/ImageSource/28383785451xxx
                                                            [width] => 1080
                                                            [height] => 1300
                                                            [url] => https://cdn.shopify.com/s/files/1/0620/5312/2211/files/preview_images/6a983a94ab784a4e97bf68c9954xxxx.thumbnail.0000000000.jpg?v=1666639534
                                                        )

                                                )

                                            [originalSource] => Array
                                                (
                                                    [url] => https://cdn.shopify.com/videos/c/o/v/6a983a94ab784a4e97bf68c9954xxxx.mp4
                                                    [width] => 1080
                                                    [height] => 1300
                                                    [format] => mp4
                                                    [mimeType] => video/mp4
                                                )

                                            [sources] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.HD-1080p-7.2Mbps-10106389.mp4
                                                            [width] => 896
                                                            [height] => 1080
                                                            [format] => mp4
                                                            [mimeType] => video/mp4
                                                        )

                                                    [1] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.m3u8
                                                            [width] => 896
                                                            [height] => 1080
                                                            [format] => m3u8
                                                            [mimeType] => application/x-mpegURL
                                                        )

                                                    [2] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.HD-720p-4.5Mbps-10106389.mp4
                                                            [width] => 598
                                                            [height] => 720
                                                            [format] => mp4
                                                            [mimeType] => video/mp4
                                                        )

                                                    [3] => Array
                                                        (
                                                            [url] => https://cdn.shopify.com/videos/c/vp/6a983a94ab784a4e97bf68c99542f31b/6a983a94ab784a4e97bf68c9954xxxx.SD-480p-1.5Mbps-10106389.mp4
                                                            [width] => 398
                                                            [height] => 480
                                                            [format] => mp4
                                                            [mimeType] => video/mp4
                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [extensions] => Array
        (
            [cost] => Array
                (
                    [requestedQueryCost] => 12
                    [actualQueryCost] => 12
                    [throttleStatus] => Array
                        (
                            [maximumAvailable] => 1000
                            [currentlyAvailable] => 988
                            [restoreRate] => 50
                        )

                )

        )

)
Array
(
    [0] => gid://shopify/Video/28367999467yyy
)

 

 


I also tried to filter for the filename:

 

 

 

$graphqlstring = '{
		 files (first: 2, query:"filename:xyz.mp4") {
and so on..

 

 

 

With this one the same problem comes up, I would expect more useful results there:

 

 

....
                                            [preview] => Array
                                                (
                                                    [status] => UPLOADED
                                                    [image] => 
                                                )
and so on..
                               

 

 

 

So I will not filter the filename but instead parse the output of the query marked with *** and compare to the original filename to make sure I get the right one.

 

friendoftheroot
Shopify Partner
48 5 8

When the upload is repeated the status READY is what to look for. It can be much further down the line than 2.

Right now I loop through the last 100 and get the first one with status READY that starts with the same string as the file name.
This is quite robust and fast as it only needs one graphQL.

friendoftheroot
Shopify Partner
48 5 8

Ok, one more update. 

I fetch all the recent fileuploads and check for the correct filename and status. That works well.

The filtering query for the originally uploaded filename did not work initially because I only tried to fetch the first:1 or first:2.
Actually the filtering query in combination with reverse is a great way to get one of those checks out of the way, so I only have to check for status.

 

One note: I do make sure that the filenames are already unique and contain the productid.

 

                        $graphqlstring = '{
					  files(first: 100, reverse:true, query:"filename:'.$arrMedia[0].'") {
						edges {
						  node {
					  
							... on Video {
							  id
							  filename
							  duration
							  preview {
								status
								image {
								  id
								  width
								  height
								  url
								}
							  }
							  originalSource {
								url
								width
								height
								format
								mimeType
							  }
							  sources {
								url
								width
								height
								format
								mimeType
							  }
							}
						  }
						}
					  }
					}
					';