How to list by multiple public IDs via the Admin API

Follow

Comments

6 comments

  • Avatar
    Bharat Nanwani

    Hi,

    Can you please help with an example to use resourcesByIds using Java Library please?

    I'm stuck on it for days now.

  • Avatar
    Nadav Ofir

    Hi Bharat,

    Here's an example from the Admin-API documentation (click the Java tab on the widget):
    http://cloudinary.com/documentation/admin_api#list_all_uploaded_images_with_the_given_ids

    Does it help?

  • Avatar
    Ryan Suntoucher

    Hi Cloudinary Support, 

    Is there a way to bulk list resources? I know that I can pass up to 100 public_ids in a single API call, but is there a way to use a next_cursor or something similar to get resources_by_ids in excess of 1000 public_ids? I'm writing a script which would update the Avatar of all users but have been road-blocked by the 100 public_id limit. If I loop through an perform an API call per user I hit the Cloudinary API rate limit of 500 transactions per hour. Any suggestions? 

  • Avatar
    Shirly Manor

    Hi Ryan,

    Here is more information of how to list all your resources using next_cursor and checking the API rate limit.

    https://support.cloudinary.com/hc/en-us/articles/205714121-How-do-I-browse-through-all-the-resources-in-my-account-using-the-API-

    Please let me know if that works for you

     

  • Avatar
    Ryan Suntoucher

    Hi Shirly, 

    Thanks for your reply. Actually rather than just browsing all resources I am looking to get information from Cloudinary about a large group of images used as Avatar images for users. 

    ```if user.avatar?
        cloudinary_public_ids << user.avatar.public_id # this returns hundreds of results
    end

    Cloudinary::Api.resources_by_ids(cloudinary_public_ids) # should return has of info about these resources

    # results in error because .resources_by_ids only allows 100 public_ids at a time
    ```

    I however found a work-around for this by using the Ruby API method ``` .in_groups_of(n)``` which would then allow me to break my array of public IDs into chunks and get my resources that way.

    ```cloudinary_public_ids.in_groups_of(100) do |cpi|
        cpi.each do |p_ids|
            results << Cloudinary::Api.resources_by_ids(p_ids)
        end
     end```

    I ended up finding a solution which didn't require making any API calls to get the necessary information, but I'm hoping this helps someone else who is trying to do something similar. 

     

  • Avatar
    Shirly Manor

    Thank you Ryan for sharing your code with Cloudinary community!

Please sign in to leave a comment.