Issues when obtaining and maintaining urls for product media of type video

Solved
nicu_taban
Shopify Partner
12 0 13

Hi!

I am developing a third-party application that uses the Shopify GraphQL API (version 2020.10) to add .mp4 videos to products. I have successfully completed the steps described in https://shopify.dev/api/examples/product-media (created an upload URL, uploaded the video and linked the video to a product).  However, the following two issues appeared:

1. The last mutation, which links the video to the product does not return any sources (empty array) or originalSource (it is null) on Media nodes of type Video. However, the video is present on the actual product in the Shopify store. The mutation is presented below:

const LINK_MEDIA_TO_PRODUCT = gql`
mutation productCreateMedia($productId: ID!, $media: [CreateMediaInput!]!) {
  productCreateMedia(productId: $productId, media: $media) {
    media {
      ...fieldsForMediaTypes
    }
    mediaUserErrors {
      code
      field
      message
    }
    product {
      id
    }
  }
}

fragment fieldsForMediaTypes on Media {
  alt
  mediaContentType
  preview {
    image {
      id
    }
  }
  status
  ... on Video {
    id
    sources {
      format
      height
      mimeType
      url
      width
    }
    originalSource {
      format
      height
      mimeType
      url
      width
    }
  }
}
`;

 

2. The second problem is that one of the functionalities of the application is to manage the videos on the products, so the application must play the videos and display them in a list. However, all the links that are present in the sources list on the Video node are CDN links. (as tested with the Shopify GraphQL application installed on the store) The documentation states that the links for Video and 3D objects stored on the CDN expire, but it does not state how long it takes for the videos to expire. In this context, how can I ensure that the users of the application can always play the videos and see a thumbnail for them? How long does it take for a video to expire?

Thank you!

Accepted Solution (1)
Luke_K
Shopify Staff
Shopify Staff
402 66 95

This is an accepted solution.

Hey @nicu_taban 

I've managed to perform some further tests here.

So the reason why originalSource is null and the sources array is empty, is due to the status of the Video media(docs) when you callproductCreateMedia. 

At point you call productCreateMedia, in a Video's case, the Video has not been fully transcoded. originalSource and sources will be returned when the Video Media status = READY (you'll note this when polling for the product's GID).

When Video media status is READY, it has completed the Transcoding and is ready to be displayed and those requested fields will be returned which is expected behaviour. 

Hope that helps explain a little more, and please let me know if you have any questions!

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!

View solution in original post

Replies 9 (9)
Luke_K
Shopify Staff
Shopify Staff
402 66 95

Hey @nicu_taban 

Thanks for raising this! With first question, Did you happen to have a request ID for that productCreateMedia mutation that I could take a look at to find out why you were getting null?

With the second question, generally our CDN cache will keep links cached for up to one year. Hope that helps!

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
nicu_taban
Shopify Partner
12 0 13

Hello @Luke_K ,

I can reproduce the behaviour, but how do I get hold of a request ID for a particular request to Shopify? Sorry for the late response.

Luke_K
Shopify Staff
Shopify Staff
402 66 95

No worries @nicu_taban!

So if you're consistently able to replicate this, we'd return an "x-request-id" in the response header when you make a call client side against Shopify API. If you send that x-request-id through to me I'll be able to see what's happening here in the logs. Thanks!

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
nicu_taban
Shopify Partner
12 0 13

Ok, so I replicated the issue in the request having the following request id: 0995e80e-b111-4e41-aad4-6149d29c98b8. If you could take a look, I would be grateful @Luke_K . Thank you!

Luke_K
Shopify Staff
Shopify Staff
402 66 95

Hey @nicu_taban 

Thanks! That helped out alot. So, I checked out the logs for that request and the job to upload the Videos runs ok,  we see the video attached to your product, all the Videos are all in the 'Ready' state (denoting that file is attached and attached to the Product).

I'm able to replicate too when directly passing in Original Source and Sources on productCreateMedia mutation, I'm returned null for originalSource and nothing in the sources array. 

As an aside, I note that when I query the Product's Graphql ID (gid) directly, much like as shown here, i'm returned data for your product's originalSource and sources array. That maybe a workaround for you in the meantime whilst we look into this further.

I'll peform some further tests here regarding expected behaviour and will endeavour to be back here as soon as I have a further update.

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
Luke_K
Shopify Staff
Shopify Staff
402 66 95

This is an accepted solution.

Hey @nicu_taban 

I've managed to perform some further tests here.

So the reason why originalSource is null and the sources array is empty, is due to the status of the Video media(docs) when you callproductCreateMedia. 

At point you call productCreateMedia, in a Video's case, the Video has not been fully transcoded. originalSource and sources will be returned when the Video Media status = READY (you'll note this when polling for the product's GID).

When Video media status is READY, it has completed the Transcoding and is ready to be displayed and those requested fields will be returned which is expected behaviour. 

Hope that helps explain a little more, and please let me know if you have any questions!

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
nicu_taban
Shopify Partner
12 0 13

Hi @Luke_K 

Following your advice, I was able to obtain the links to the productMedia!

I have some final questions regarding the CDN, The productMedia object contains a sources array and an originalSrc field. Can I rely on the fact that the link in the originalSrc will not expire?

Also, the productMedia object has a preview field which is an object containing a thumbnail image, which in turn contains an originalSrc field. Can I also rely on the fact that the originalSrc for the thumbnail will not expire?

Thank you very much!

Luke_K
Shopify Staff
Shopify Staff
402 66 95

Hey @nicu_taban 

Yes you can rely on those to not expire. The documentation actually needs a refresh -  I believe those docs were written at a point where our Video Source URL's would expire. Hope that helps!

 

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
nicu_taban
Shopify Partner
12 0 13

Thank you very much for your clarifications @Luke_K !