2

I am trying to add video media to product using REST API. Example below

$data = [   'entry' => [
      'id' => null,
      'media_type' => 'external-video',
      'label' => null,
      'position' => 0,
      'types' => ['image', 'small-image', 'thumbnail'],
      'disabled' => false,
      'content' => [
          'base64_encoded_data' => base64_encode(file_get_contents('http://img.youtube.com/vi/axwE9q7llEQ/0.jpg')),
          'type' => 'image/jpeg',
          'name' => '0.jpg'
      ],
      'extension_attributes' => [
          'video_content' => [
              'media_type' => 'external-video',
              'video_provider' => 'youtube',
              'video_url' => 'https://www.youtube.com/watch?v=axwE9q7llEQ',
              'video_title' => 'KęKę',
              'video_description' => null,
              'video_metadata' => null
          ]
      ]   ] ];

$ch = curl_init("http://URL/index.php/rest/V1/products/BICUMD2ndXXX036/media"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));

curl_exec($ch);

At the end I am receiving new media file ID but in admin I see that some fields like video url or description are empty. Any idea what I am doing wrong?

2
  • Hi @rafal-kos I've the same issue! Did you found the solution? Commented Jan 10, 2017 at 15:58
  • Yes. I am calling first API request and after that I am calling direct sql queries with missing data $sql = "UPDATE catalog_product_entity_media_gallery_value_video SET store_id = 0, url = :url, title = :title WHERE value_id = :valueId"; $connection->query($sql, ['url' => $url, 'title' => $title, 'valueId' => $videoId]); $sql = "UPDATE catalog_product_entity_media_gallery_value SET store_id = 0 WHERE value_id = :videoId"; $connection->query($sql, ['videoId' => $videoId]); `
    – rafal-kos
    Commented Jan 11, 2017 at 16:26

3 Answers 3

4

If anyone is struggling with this, it's fixed in Magento 2.1.8 EE:

http://devdocs.magento.com/guides/v2.1/release-notes/ReleaseNotes2.1.8EE.html#web-api

and Magento 2.1.8 CE:

http://devdocs.magento.com/guides/v2.1/release-notes/ReleaseNotes2.1.8CE.html#web-api

0

In version CE 2.1.11 I need to add the 'all' indication to the URL to circumvent the same problem. So: http://URL/index.php/rest/all/V1/products/BICUMD2ndXXX036/media instead of: http://URL/index.php/rest/V1/products/BICUMD2ndXXX036/media

0

I managed to add a video using rest API, check this link I explain what I did :

https://github.com/magento/magento2/issues/7153#issuecomment-414727820

Hope it help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.