How to get a media library document's tags in a related query

Hi everyone,

Stupid question: how do I retrieve the tags associated to a media library document?

Say that I've linked some pictures to a page via a repetitive image field, and I'm querying the page. Currently, the API returns this sort of thing:

[
 {
    dimensions: { width: 2048, height: 2048 },
    alt: null,
    copyright: null,
    url: 'https://images.prismic.io/xyz/zsdsd-06.jpg?auto=format,compress',
    id: 'xyz',
    edit: { x: 0, y: 0, zoom: 1, background: 'transparent' }
 }
]

I have everything but the tags.

Any idea? Do I need to query the media library specifically in order to get these tags?

Thanks
Tom

Hello Tom,

Thank you for your question about retrieving tags associated with media library documents in Prismic. This is not a stupid question at all, and I'm happy to help clarify this for you.

Currently, there isn't a direct way to retrieve tags for media library items through the standard document queries. The API response for image fields includes information such as dimensions, alt text, copyright, URL, and some editing metadata, but not tags.

For now, if you need to associate tags with your images, you might consider creating a custom field in your document model to store tags for each image, rather than relying on the media library tags.

Let me know if you have any further questions.

Thanks.

Hi Phil,

Thanks for your response. It's such a shame that it's not a feature.

I see no point of using tags for the Media Library if it's only an UI trick...

Thanks,
Tomas

I wouldn't say it's a trick; it's a tool for organising and searching media and relatively new one at that.

Though I agree it's a useful feature request. Although what I think would be the ideal case is if we had a tags field included which was prepopulated from the tags from the media library which you could edit on the page level. Like the alt text field seen below:

This way we can manage multiple instances of these tags without affecting the base tags.

I'll pass this feature request on to the team.

Thanks for your input Tom :slight_smile:

Also, can you give me your exact use case for this?

I’d imagine it’s for filtering an image gallery.