Internal usage of the API to search medias with a specific mime_type?

I have been trying to use the API to query the database and find all medias with a specific mediaType/mimeType.

i have tried multiple variations of this kind of line:

$response = $this->api->search('media', ['mime_type' => "application/pdf"])->getContent();

But I have not been able to reach a point where this line would thrown the expected medias, I always get the same medias, not limited to PDF, as if the array was not considered. Based on the rest API doc I understand that MIME type might not be a search critera but I am then wondering what is the best way to get all PDF files from the database.

I believe I could rely on a SQL query, but I would prefer using the API if there is any way to do it.


You currently can’t do this through the API: as you say, we just don’t provide a parameter for searching on mime type.

It’s a good feature request, though.

Thanks @jflatnes for confirming this. I have now created PR #1463 on github to add an option to allow search by media_type.

For information, this feature is already available in the module Advanced Search.

A post was split to a new topic: Selecting all items in API