Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

Product Add External Video

Product Add External Video

thintqdev
Shopify Partner
1 0 0

I want to insert Youtube or Vimeo video via API productCreate.

My GraphQL is here

mutation productCreate($input: ProductInput!, $media: [CreateMediaInput!]) {
  productCreate(input: $input, media: $media) {
    product {
      id
      title
      descriptionHtml
      vendor
      productType
      status
      collections(first:10){
          edges{
              node{
                  id
              }
          }
      },
      tags
      seo{
          title
          description
      }
      variants(first: 10) {
        edges {
          node {
            selectedOptions {
              name
              value
            }
            price
            inventoryItem{
                unitCost{
                    amount
                },
                tracked
            }
            inventoryQuantity
            sku
            compareAtPrice
            weight
            weightUnit
            barcode
            media(first: 10) {
              edges {
                node {
                  ... on Video{
                      originalSource{
                          url
                      }
                  }

                  ... on ExternalVideo{
                      embedUrl
                  }
                  ... on MediaImage {
                    id
                    alt
                    image {
                      url
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

My GraphQL Variable here

{
 "media": [
   {
     "mediaContentType": "IMAGE",
     "originalSource": "https://i.ebayimg.com/thumbs/images/g/euMAAOSw-exg9ZP0/s-l300.jpg"
   },
   {
     "mediaContentType": "IMAGE",
     "originalSource": "https://mcdn.nhanh.vn/store/2071/ps/20220524/Untitled_2.jpg"
   },
   {
       "mediaContentType":"VIDEO",
       "embedUrl":"https://www.youtube.com/watch?v=ojkdEdLnIaA"
   }
 ],
 "input": {
   "title": "A-T-shirt",
    "descriptionHtml":"sản phẩm A-T-shirt",
   "options": [
     "Color", "Size"
   ],
   "vendor":"QT",
   "productType":"A-T-shirt",
   "collectionsToJoin": [
      "gid://shopify/Collection/394135732463"
    ],
    "tags":["shirt", "white"],
    "seo":
        {
        "title":"A-T-shirt",
        "description":"Sale"
        }
    ,
   "variants": [
     {
       "mediaSrc": ["https://cdn.come/red_t_shirt.jpg"],
       "options": ["Red", "M"],
       "sku":"123",
       "price":100,
       "compareAtPrice":123,
        "weight":1.0,
        "weightUnit":"KILOGRAMS",
        "barcode":"123",
        "inventoryItem": {
          "cost": 1230,
          "tracked": true
        },
        "inventoryQuantities": {
          "availableQuantity": 100,
          "locationId": "gid://shopify/Location/68643782895"
        }
     },
     {
       "mediaSrc": ["https://cdn.come/red_t_shirt.jpg"],
       "options": ["Red", "L"],
       "sku":"123",
       "price":100,
        "inventoryItem": {
          "cost": 1230,
          "tracked": true
        }
     },
     {
       "mediaSrc": ["https://cdn.come/yellow_t_shirt.jpg"],
       "options": ["Yellow", "M"],
       "sku":"123",
       "price":100,
        "inventoryItem": {
          "cost": 1230,
          "tracked": true
        }
     },
     {
       "mediaSrc": ["https://cdn.come/yellow_t_shirt.jpg"],
       "options": ["Yellow", "L"],
       "sku":"123",
       "price":100,
        "inventoryItem": {
          "cost": 1230,
          "tracked": true
        }
     }
   ]
 }
}

But it has this error: 

 "Variable $media of type [CreateMediaInput!] was provided invalid value for 2.embedUrl (Field is not defined on CreateMediaInput), 2.originalSource (Expected value to not be null)"
 
Please help me to fix this issue. Thank you so much.
Replies 0 (0)