search API subfolder

eemeals
eemeals Member Posts: 1

Hi! I am new to Cloudinary so bear with me... Right now the following code grabs all of my Cloudinary media, but I just need assets from a folder/subfolder. How can I specifically grab assets within a particular folder using the Cloudinary search API? Thanks!


const results = (await cloudinary.v2.search

  .expression(`resource_type: image`)

  .sort_by('public_id', 'desc')

  .max_results(100)

  .execute())

Tagged:

Answers

  • Cloudinary Team
    Cloudinary Team Administrator, Cloudinary Staff Posts: 92 admin

    Hi there,

    Thanks for reaching out.

    You can use the 'folder' expression field to get the assets in a particular folder. Here is an example of querying for assets in a folder called 'cats':

    cloudinary.search.expression("folder=cats").execute().then((result) => console.log(result));.catch((err) => console.log(err));
    

    You can refer to the documentation for additional information on expression fields here:
    https://cloudinary.com/documentation/admin_api#expression_fields

    I hope this helps. Please give it a try and let us know if you have any questions.
    Kind regards,

    Tia

    Helpful Links For You
    💬 Share questions, connect with other users in our Cloudinary Community forums and Discord server!
    🧑‍🎓 Join our Cloudinary Academy for free courses, workshops and other educational resources.
    📄 Read our documentation for in-depth details on Cloudinary product features and capabilities
    📰 Check out the Cloudinary blog for the latest company news and insights