• Resolved samsup

    (@samsup)


    Hi,

    I am trying to work out a way to bulk update my images in woocommerce, and am getting stuck already in postman trying to figure out how to update the image source link in a product.

    Whenever I PUT the following:
    {
    “name”: “testproduct”,
    “images”: [
    {
    “id”: 20435,
    “src”: “https://www.mywebsite/com/images/testimage.jpg”,
    “position”:0
    } ]

    }
    to the correspondings product endpoint; whenever I make a change to the “name” it works as intended, the postman response gives back the changed name ( and ofcourse the entire related product Json), however the image link always remains the stuck to be the old link.

    "images": [
            {
                "id": 20435,
                "date_created": "2021-06-30T13:02:27",
                "date_created_gmt": "2021-06-30T13:02:27",
                "date_modified": "2021-07-11T13:14:19",
                "date_modified_gmt": "2021-07-11T13:14:19",
                "src": "https://www.mysite.com/wp-content/uploads/2021/06/testimageold.jpg",
                "name": "testingproduct",
                "alt": "testingproduct "

    I found earlier posts having similar issues and they mention to include the image ID in the PUT, and position for good measure, but removing or using this has no effect.
    as far as I can tell, the image location is freely accesible, so I dont see why this would not work. Does anybody have an idea where I am going wrong?

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter samsup

    (@samsup)

    Okay so an update to this issue I am running into;

    I can modify image name, and altname via the postman PUT command. I have been succesfull in updating various other arrays too. The only thing at this point not working is updating the image “src” link. Whenever I drop a paypload it will update all fields fine, just not the image “src” ones. It gives status 200, so no errors.

    Unless there is another way this should be done..simply dropping the files in with FTP clearly doesnt work to bulk replace images, and linking each image separately by hand is not an option with over 4000 products to update. My idea was to have a little script in my database program crawl trough each product and just update the image source link in woocommerce by using the REST API to link to the new image ( image is present on the server, accesible via http), and hoped that woocommerce would be able to pick that up.. but this seems to be impossible too. Also failing to add a second picture by just uploading the “src” imagelink without imageID (from what I gather it should then create a second image)
    I have tried to find more correct methods of mass updating images in woocommerce, but have been unsucessfull in finding somethhing that works for us.

    Mirko P.

    (@rainfallnixfig)

    Hi @samsup,

    It is very important to send the correct JSON syntax and it looks like yours is missing a double quote.

    You can send this request and let’s hope it works.

    {
        "name": "testproduct",
        "images": [
            {
            "src":"https://www.mywebsite/com/images/testimage.jpg",
            "position": 0
            }
        ]
    }

    Cheers.

    Thread Starter samsup

    (@samsup)

    Hi Mirko,

    Thank you for the suggestion. I must have made a typo when redacting the link, but I can confirm that I have been doing the put request with the correct double quote..

             "images": [
            {
                "id": 20435,
                "date_created": "2021-06-30T13:02:27",
                "date_created_gmt": "2021-06-30T13:02:27",
                "date_modified": "2021-07-11T13:14:19",
                "date_modified_gmt": "2021-07-11T13:14:19",
                "src": "https://www.https://samsup.com/images/0260101.jpg",
                "name": "test",
                "alt": "test "}],
    

    it returns:

    
    
    "images": [
            {
                "id": 20435,
                "date_created": "2021-06-30T13:02:27",
                "date_created_gmt": "2021-06-30T13:02:27",
                "date_modified": "2022-05-05T17:32:26",
                "date_modified_gmt": "2022-05-05T17:32:26",
                "src": "https://www.samsup.com/wp-content/uploads/2021/06/0260101.jpg",
                "name": "test",
                "alt": "test"
            }
        ],
    • This reply was modified 4 years, 1 month ago by samsup.
    • This reply was modified 4 years, 1 month ago by samsup.
    • This reply was modified 4 years, 1 month ago by samsup.
    Thread Starter samsup

    (@samsup)

    I can by the way also confirm that I have tried to do the request without the read only datapoints of ` “date_created”: “2021-06-30T13:02:27”,
    “date_created_gmt”: “2021-06-30T13:02:27”,
    “date_modified”: “2022-05-05T17:32:26”,
    “date_modified_gmt”: “2022-05-05T17:32:26”,

    Mirko P.

    (@rainfallnixfig)

    Hi @samsup,

    I’ve been testing this on my local install using Postman and it’s definitely working.

    Make sure you enter the URL correctly (i.e. https://samsup.com/images/0260101.jpg).

    If you still can’t get it to work, this is my setup and it’s confirmed that it’s running smoothly.

    Postman PUT request


    Full Size: https://snipboard.io/2izWbY.jpg

    Product image before sending the request

    Product image after sending the request

    Hope this helps.

    Thread Starter samsup

    (@samsup)

    Hi Mirko,

    I am doing the exact same thing, as far as I can tell..
    below image of what I am doing

    https://snipboard.io/G4v3IQ.jpg

    The response keeps giving back the old link location. I have tried above with Put, Patch and Post, all give the same response. I can update any value in the product Json, except for the image link.. Is there some setting somewhere that might be causing the change of images to become impossible? Either in the server settings, woocommerce or wordpress settings?

    • This reply was modified 4 years, 1 month ago by samsup.
    Mirko P.

    (@rainfallnixfig)

    Hey @samsup,

    Can you try without the image id?

    Since there’s only one main product image you can skip that and it should work.

    Let us know how it goes.

    Thread Starter samsup

    (@samsup)

    Mirko, your suggestion works, partially. I can in fact confirm that I can now modify images when not using the imageID.

    This however creates the problem that the media library keeps generating new images every time I do an API call ( so by now I have for product 0260101, I have 0260101.jpg, 0260101-2.jpg, 0260101-3.jpg, 0260101-4.jpg, which are all 4 copies of the same image ( for the 4 PUT requests I did) When I change the image to for example 0260101test.jpg, it creates that image, and when I PUT it agian, it creates another 0260101test-1.jpg for example.
    This would ofcourse overflow my server after a few iterations of doing this.

    From what I read in other topics regarding images and API, the solution to that would be to include the imageID.. but when I include imageID, I am not able to update/change the image at all, wether it has same filename, or new filename to an existing image in the library.

    I tried using DELETE call with the image but that just trashes the whole product.. so thats a no go..

    so essentially whats left is to find a way to remove the entire picture library every time I want to mass update images? There must be a more “correct” way to remove unused images right?

    Hi @samsup

    Thanks for testing that.

    find a way to remove the entire picture library every time I want to mass update images? There must be a more “correct” way to remove unused images right?

    Just to let you know that for development related questions you can also get help at the following channels, as this forum is more focused on WooCommerce core features:

    Hoping for a quick resolution.

    Cheers

    Margaret S. woo-hc

    (@margaretwporg)

    This thread has been inactive for a bit, so I’m going to mark it as closed. Hopefully, the above information was useful to you.

    Please feel free to open a new thread if you have any other questions.

    Thread Starter samsup

    (@samsup)

    Hello,

    Yes thank you all for the information and help. The result is different than expected at first, but essentially it all works. It would be good to explain the mechanics of images a bit more deeply in the API documentation maybe, as I would imagine more people are strugling to grasp how the library does its magic.

    But long story short, picture update via API works, however the JSON response is not going to be the image link ( which is what I expected) but it is rather going to be the newly created imagelink in the medialibrary.

    The only thing that I could not get to work is to update an image ( overwrite in the library) using the imageID, so I am stuck at just creating new images, but perhaps that is not thet intended fuction of the API ( hence it would be good to more deeply explain the documentation here).

    As for creating endless duplicates, it is not optimal, but easily manageable with a plugin that sanitizes unused images.

    so on my end, I was able to do everything I needed to do!

    Margaret S. woo-hc

    (@margaretwporg)

    Hi @samsup

    Good to know that you were able to do everything that you needed to do.

    Thanks for providing the details. Although this forum is for issues related to the WooCommerce core features, these details will be helpful to others facing a similar problem.

    It would be good to explain the mechanics of images a bit more deeply in the API documentation maybe, as I would imagine more people are strugling to grasp how the library does its magic.

    The only thing that I could not get to work is to update an image … it would be good to more deeply explain the documentation here)

    Thanks for sharing these helpful suggestions about improving the documentation.

    Feel free to create another topic if you need help with anything else.

    Cheers

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘REST API not updating image link’ is closed to new replies.