skip to Main Content

Magento version 2.2.5
Endpoint in question /V1/products/{sku}/media METHOD: POST

I am trying to add a video under a product sku using Magento’s provided API endpoint.

{
 "entry": {
     "media_type": "external-video",
     "label": "Video 2",
     "position": 2,
     "disabled": false,
     "types": ["thumbnail"],
     "content" : {
         "base64_encoded_data": "encoded image data ",
         "type": "image/jpeg",
         "name": "0.jpg"
     },
     "extension_attributes": {
         "video_content": {
             "media_type": "external-video",
             "video_provider": "youtube",
             "video_url": "some youtube video url",
             "video_title": "some title",
             "video_description": "",
             "video_metadata": ""
         }
     }
}

The response I get from this call is “invalid option value”, I had debugged this in a local environment which leads me to failure during ProductRepository->save() within MagentoCatalogModelProductGalleryGalleryManagement.php on line 70.

Is this an issue with my payload or actual magento bug?

2

Answers


  1. Chosen as BEST ANSWER

    Resolved this issue by adding videos directly using POST /V1/products or PUT /V1/products/{sku} endpoints.

    post method example:

    { 
      "product": {
         "sku": "some-sku",
         ..... other product data,
         "media_gallery_entries": {
             "media_type": "external-video",
             "label": "Video 2",
             "position": 2,
             "disabled": false,
             "types": [],
             "content" : {
                 "base64_encoded_data": "encoded image data ",
                 "type": "image/jpeg",
                 "name": "0.jpg"
              },
              "extension_attributes": {
                  "video_content": {
                      "media_type": "external-video",
                      "video_provider": "youtube",
                      "video_url": "some youtube video url",
                      "video_title": "some title",
                      "video_description": "",
                      "video_metadata": ""
              }
         }
       }
    }
    

    I had no luck with Magento's MediaGallery POST endpoint (/V1/products/{sku}/media.


  2. If you want to add a video to the product page then why you did not try using YouTube API?

    You just need to follow these steps:

    • Generate a YouTube API Key by going goodle developer console
    • Then add Youtube API key to your Magento 2 by going to STORES –> Configuration
    • Then Add Video URL
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search