What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Invalid URL when attaching videos to a product

Solved

Invalid URL when attaching videos to a product

kryniol
Tourist
5 0 4

Hi!

 

I'm trying to upload and attach a video to a product by following this guide: https://help.shopify.com/en/api/guides/media

I successfully obtained the credentials, then sent the upload request to the given S3 bucket and received an URL of the uploaded asset. Now I'm trying to attach it to a product using the productCreateMedia GraphQL mutation (I'm using the unstable API version):

 

		mutation createProductMedia($id: ID! $media: [CreateMediaInput!]!) {
			productCreateMedia(productId: $id, media: $media) {
				media {
					status
					... on Video {
						id
					}
					... on ExternalVideo {
						id
					}
					mediaErrors {
						code
						details
						message
					}
				}
				userErrors {
					field
					message
				}
			}
		}

 

with following variables:

 

{ 
   "id":"gid://shopify/Product/4163879075922",
   "media":[ 
      { 
         "originalSource":"https://shopify-video-production-core-originals.s3.amazonaws.com/c/o/v/8497841fa3794b098b2a41a8ad3353c4.mp4",
         "mediaContentType":"VIDEO"
      }
   ]
}

 

But every time I send the request I get the following error from the API:

 

{
  "data": {
    "productCreateMedia": {
      "media": [],
      "userErrors": [
        {
          "field": [
            "media",
            "0",
            "originalSource"
          ],
          "message": "Invalid video url=https://shopify-video-production-core-originals.s3.amazonaws.com/c/o/v/8497841fa3794b098b2a41a8ad3353c4.mp4"
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 11,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 990,
        "restoreRate": 50
      }
    }
  }
}

Is it a bug in the API? Or should I use some different value as an originalSource variable when attaching the video to the product?

Thanks in advance for any help!

Accepted Solution (1)

amosmos
Shopify Partner
89 1 32

This is an accepted solution.

I think you should use the "resourceUrl" you're getting back from the `stagedUploadsCreate` mutation,

and from the looks of it it seems you are sending the `url` field instead.

 

Amos

View solution in original post

Replies 4 (4)

OTM
Shopify Partner
696 170 252

Hi, @kryniol,

 

This is Evita from On The Map.

 

It looks like your video URL is broken.

 

Best,
Evita

On The Map Marketing | Developing custom Shopify Sites & Apps is our thing

- Install our latest app Accessibly - Makes your store accessible for everyone, helps to avoid fines
- Inc 5000 | Shopify Parners | 20+ stores launched | 300+ active clients
- Need help with your Shopify store? Reach out to us!

amosmos
Shopify Partner
89 1 32

This is an accepted solution.

I think you should use the "resourceUrl" you're getting back from the `stagedUploadsCreate` mutation,

and from the looks of it it seems you are sending the `url` field instead.

 

Amos

kryniol
Tourist
5 0 4

Thank you @amosmos VERY VERY VERY much! I owe you one! Now it works like a charm 🙂

amosmos
Shopify Partner
89 1 32

Happy to help 🙂