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?

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Sep 22, 2016 at 11:02
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]); ` Commented Jan 11, 2017 at 16:26

3 Answers 3

4
answered Aug 17, 2017 at 14:07
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

answered Mar 27, 2018 at 9:21
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.

answered Aug 21, 2018 at 16:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.