#How to get the title of a file via RestAPI?

4 messages · Page 1 of 1 (latest)

thin hatch
#

I have a collection called "playlist" that has an m:m-relational field to a files field. There all the mp3 files that were perviously uploaded, are referenced.
Now I would like to get a specific playlist (id=14) that also returns the title of each of those mp3 fields. I understand that information is written to a Directus table. How can I get it via RestAPI? (The Goal is to list the file titles and link them to the audio file, so that on click the audio is played.)

This is the API call at the moment:

https://[domain]/items/playlists/14?filter[status][_eq]=published&fields=title,additional_title,description,slug,audio_files.*

which returns a result like this:

{
  "data": {
  "title": "Playlist of all compositions",
  "additional_title": null,
  "description": null,
  "slug": "playlist-of-all-compositions",
  "audio_files": [
  {
    "id": 69,
    "playlists_id": 14,
    "directus_files_id": "c025fc41-1465-4d9d-961a-39cbc64c0646"
  },
  {
    "id": 70,
    "playlists_id": 14,
    "directus_files_id": "d12b29b6-0141-4e3e-8fa5-9f7aee3d2e30"
  },
  { [...]
summer ibexBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please make sure your question includes the following:

  • An explanation of exactly what you're trying to achieve.
  • Any and all related code or previous attempts.
  • The exact issue or error you are facing.
  • Any screenshots if applicable.

When you're done with this thread, please close it.

(If you have a support agreement and need help, please contact the core team via email.)

thin hatch
#

Anybody with an idea how to query m:m data?

flat heart
#

because M2M relations make use of a junction table you'll need an extra level of nesting in your fields:
&fields=audio_files.directus_files_id.*