How to delete images with the same delivery type

Options
Chen_Friedman
Chen_Friedman Member Posts: 1
edited December 2022 in Developer APIs

Hello!


We have a lot of images in the main "home" folder and I want to delete them by API, but don't know how:

Example of image:

https://res.cloudinary.com/hcabpjybe/image/fetch/v1671118388/https://protected.chatleap.com/5f844911f82aaa4ac4b98df8/PZ9RcftcDh2WfjO-8izE.jpeg

I want to delete all the assets that have "5f844911f82aaa4ac4b98df8" in the link

How can I find them?


Thank you!

Answers

  • rlux
    rlux Administrator, Cloudinary Staff Posts: 63
    Options

    If you want to delete multiple assets at the same time, you can use the delete resources method of the Admin API. If the assets you want to delete are of the same structure as the URL you shared, you could pass https://protected.chatleap.com/5f844911f82aaa4ac4b98df8/ as the prefix to the delete_resources_by_prefix method. Note that the default type is upload, so if these are fetched images, you will also need to pass the type parameter and set that to fetch.

    So an example of what that might look like is as follows:

    cloudinary.api
        .delete_resources_by_prefix("https://protected.chatleap.com/5f844911f82aaa4ac4b98df8/", {
            type: "fetch",
        })
        .then((result) => console.log(result))
        .catch((error) => console.error(error));
    
    

    You can reference the documentation here on the delete resources method of the Admin APi:

    https://cloudinary.com/documentation/admin_api#delete_resources