cancel
Showing results for 
Search instead for 
Did you mean: 

How to import product image from external url using API

SOLVED

How to import product image from external url using API

Hello guys,

 

I have the situation where I need to pass product image url using API.

I am receiving product info from few vendors by AP, I need to display product image from external url on magento product page, any ideas how to implement this?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to import product image from external url using API

As always Smiley Very Happy I ask first then I answer myself. Here's the solution I was looking for, code is in python:

from urllib.request import urlopen 
import base64

data=base64.b64encode(urlopen(" ").read())
imageEncoded=data.decode('utf-8')

then it passes to base64_encoded_data according to /rest/default/V1/products/{sku}t/media

{
  "entry": {
      "mediaType": "image",
      "position": 0,
      "disabled": false,
      "types": [
            "image",
            "small_image",
            "thumbnail",
            "swatch_image"
        ],
      "content":{
        "base64_encoded_data" : "",
        "type": "image/jpeg",
        "name":"pic_name.jpg"
    }
  }
}

View solution in original post

1 REPLY 1

Re: How to import product image from external url using API

As always Smiley Very Happy I ask first then I answer myself. Here's the solution I was looking for, code is in python:

from urllib.request import urlopen 
import base64

data=base64.b64encode(urlopen(" ").read())
imageEncoded=data.decode('utf-8')

then it passes to base64_encoded_data according to /rest/default/V1/products/{sku}t/media

{
  "entry": {
      "mediaType": "image",
      "position": 0,
      "disabled": false,
      "types": [
            "image",
            "small_image",
            "thumbnail",
            "swatch_image"
        ],
      "content":{
        "base64_encoded_data" : "",
        "type": "image/jpeg",
        "name":"pic_name.jpg"
    }
  }
}

View solution in original post