3
votes

What might be a reason? Trying to batch update product images (and price) in WooCommerce via REST API. Images already exist in wordpress media library and links are correctly copied. However, instead of using image it creates new image.

Request: POST. URL: https://SiteURL/wp-json/wc/v2/products/xxxx?consumer_key=c______&consumer_secret=_____

Body:

 {"update":[
      {"regular_price":"448",
         "images":[
             {"src":"https://urlToImage.jpg",
               "position":0, "name": "test"}
      ],"id":"xxxx"}]}

In response I can see it creates image with the same url but as there is already an image in the library, it adds -1 to url.

Thank you in forward :)

1

1 Answers

6
votes

Since this is an update where the images already exists you need to set the id member of the images element. Otherwise, WooCommerce interprets this as a request to add a new image to the product gallery.