Error on GraphQL mutation

DennisTastic
New Member
7 0 0

So I finally figured out how to upload a productvideo by way of graphQL (hurray). But I keep getting back the error that my URL string is incorrect. I tried a bunch of variations on the URL but it doesnt to work. I've added the call and response to elaborate, thank you in advance.

The call:

mutation {
    product(id: 34283482513547)
    embeddedUrl: "www.youtube.com/watch?v=noKpc8fo-R0"
}

The Response: 

{
   "error": "783: unexpected token at 'mutation {\n\tproduct(id: 34283482513547)\n\tembeddedUrl: \"www.youtube.com/watch?v=noKpc8fo-R0\"\n}'"
}

0 Likes
Greg_Kujawa
Shopify Partner
953 80 203

This doesn't seem to jibe with the API documentation and examples I see here --> https://shopify.dev/tutorials/manage-product-media-with-admin-api. Although I personally haven't run through this in production on my end. 

DennisTastic
New Member
7 0 0

Thanks for your reply, due to your post I was able to get it working Postman. This issued the next problem which is that Postman has two seperate fields, on for functions and the other for variables. In the enviroment that I use I've got only one field to put it all. So I figured something like this.

"productId" : "gid://shopify/Product/5062835536011"
"media" : [
	{
		"originalSource": "https://www.youtube.com/watch?v=1jv_OzJXvow",
    	"mediaContentType": "EXTERNAL_VIDEO"
    }
  ]

mutation productCreateMedia($productId: ID!, $media: [CreateMediaInput!]!) {
  productCreateMedia(productId: $productId, media: $media) {
    media {
      alt
    }
    mediaUserErrors {
      code
      field
      message
    }
    product {
      id
    }
  }
}

 The problem here is probably something syntax like but I can't seem to find it. The error that it returns is 783, without a line number/ character number. My question to the forum is: Where is the syntax error located and how do I solve it? 

Any help is much appreciated, yours sincerely,

Dennis

0 Likes
Greg_Kujawa
Shopify Partner
953 80 203

Using Postman I recall initially having some issues between properly formatting the JSON request body, properly setting the header values, etc. Plus selecting the (seemingly intuitive choice) GraphQL body type didn't really work off the bat. I haven't looked at it in awhile, but here are some screen shots from a successful Postman GQL request/response pair. Please note the things I've boxed in red. Should work!

1.jpg2.jpg 

0 Likes