Media Library

Query aspects

Query aspects in the Media Library dataset.

When you create and deploy an aspect, it's stored in the Media Library dataset alongside your asset documents. In this guide, you'll query your Media Library based on your aspects.

Prerequisites:

  • API version v2025-02-19 or later

The examples below use JavaScript's fetch to perform API calls, but the same principles apply regardless of the language or request library.

List all aspects

Aspects are Sanity documents with a _type of sanity.asset.aspect. You can query them with GROQ using the Media Library's query endpoint.

Like other Sanity queries, you'll receive a response containing the original query, a result, sync tags, and the response time. Here's an example response for a single field, boolean aspect:

Query assets by aspect details

Any asset document in your library that has an assigned aspect will include those aspect details in an aspects property. You can query for specific aspect information using GROQ and the Media Library's query endpoint.

As an example, if you want to query all assets that have the placeholder aspect set to true, you can perform the following query.

The above request returns any sanity.asset document with the placeholder aspect set to true.

POST instead of GET

You can also query with a POST request. Instead of using the ?query= parameter, set the body to your stringified query, the method to POST, and the Content-type to application/json. Here's the same example above, but as a POST.

Was this page helpful?