Magento – Add video to product programatically

magento2mediaproductproduct-attributevideo

OK, I have some bundled product to create and I want to do it programatically.

Problem is, I want to add (to MediaGallery) some videos, as it can be done in case of images. It can be done via adminhtml product edit form and works like a charm. So far I have found module-product-video in vendor. I'm not sure if that's it.

I think maybe I should use then VideoEntryFactory and bind it with product instance but I am not sure. In Model of Product i haven't found method similar to addImageToMediaGallery.

If anyone have faced it, please give me some advices.

Best Answer

you can use the rest api POST /V1/products/{sku}/media

{
  "entry": {
    "id": 0,
    "mediaType": "string",
    "label": "string",
    "position": 0,
    "disabled": true,
    "types": [
      "string"
    ],
    "extensionAttributes": {
      "videoContent": {
        "mediaType": "string",
        "videoProvider": "string",
        "videoUrl": "string",
        "videoTitle": "string",
        "videoDescription": "string",
        "videoMetadata": "string"
      }
    }
  }
}
Related Topic