πŸ“£ The forum has moved to GitHub

We’ve switched to GitHub Discussions as the hub for our community. This will improve the experience of collaborating for everyone, sharing what you’re working on, and discussing ideas for how Swell can be improved. Existing threads will remain open, but new posts are disabled.

Go to GitHub β†’

Images documentation: how to use the api to import images from another domain

I have a client that has about 3700 products in a woo-commerce site. We're looking to move them over so I spent the weekend building out an importer with the api. When I import images using the URL of the product they get stored using that original URL.

This is problematic because once we turn off that woo-commerce instance all those product images will not be accessible.

Is there a better way to import products with images through the api? The documentation seems to have gaps when it comes to images. I can't find a single example of a payload for any of the posts or puts that shows how images should be uploaded so I'm not sure if I'm missing anything.

I also tried converting them to base64 and attaching them using the data property in the file object of the image but after the import the images were all blank.


Just looking any advice if anyone's run into a similar situation, thank you,

Answers

  • Here's an example using `swell-node`

    swell.put('/products/{id}', {
      id: productId,
      images: [
        {
          id: imageId, // if updating an existing image, otherwise it will create a new one
          data: { $base64: imageDataInBase64 },
    
          // optional properties
          metadata: { ... }, // object with custom props
          filename, // i.e. 'cars.png'
          content_type, // i.e. 'img/png'
    ο»Ώ      width, // default width
          height, // default height
        }
      ]
    })
    
  • Thanks Eric, I'll give that a shot, I suspect my base64 conversion wasn't 100% correct form the original images, because what you shared is pretty much exactly what i had tried. However, as I mentioned when I previewed the uploaded product the images were blank which makes me think I had the api part right just not the base64 conversion. But thank you for sharing it does help give me a confirm what the shape of the payload should look like :-)

Sign In or Register to comment.