# REST API Questions

**URL:** <https://discourse.mopidy.com/t/rest-api-questions/1024>\
**Category:** Misc\
**Created:** [December 23, 2015, 4:05pm UTC](https://discourse.mopidy.com/t/rest-api-questions/1024 "2015-12-23T16:05:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klieber\_frederic](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Klieber\_frederic](https://discourse.mopidy.com/u/Klieber_frederic)\
**Post date:** [December 23, 2015, 4:05pm UTC](https://discourse.mopidy.com/t/rest-api-questions/1024/1 "2015-12-23T16:05:54Z")

</div>

Hello,

I’ m just trying to figure out how the APi responses to the request :

**How can I list all artists from a given genre ?**  
**All Albums from a given artist ?** -+

I would like to write a frontend in python, which would be easier for me to do than the same thing in javascript or nodejs.The frontend will be Album oriented and suitable for a TV remote and a TV display.

Thanks for your response.

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [December 23, 2015, 4:41pm UTC](https://discourse.mopidy.com/t/rest-api-questions/1024/2 "2015-12-23T16:41:44Z")

</div>

The documentation is at [https://docs.mopidy.com/en/latest/api/core/#mopidy.core.LibraryController.search](https://docs.mopidy.com/en/latest/api/core/#mopidy.core.LibraryController.search)

You may find the API explorer useful for getting a feel for things: [https://github.com/dz0ny/mopidy-api-explorer](https://github.com/dz0ny/mopidy-api-explorer)

---

<div class="post-metadata">

**Author:** ![Klieber\_frederic](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Klieber\_frederic](https://discourse.mopidy.com/u/Klieber_frederic)\
**Post date:** [December 24, 2015, 2:16am UTC](https://discourse.mopidy.com/t/rest-api-questions/1024/3 "2015-12-24T02:16:20Z")

</div>

Thank you kingosticks for your reply.  
I have already read the documentation and also installed api-explorer.  
I have previously worked with numerous online API’s ( 7, including this from TMDB , you can see it here [https://github.com/fredele](https://github.com/fredele)

But this API gives me some headache … I explain:

The search functions gives me a dict. with a result key with is a list.  
Is the length of this list always 1 ?

In the result key I got a tracks key wich contains all the tracks.  
A track has an album key, and other keys like name, uri,genre, artists.  
But the album key has also an artists key ?  
Is the artist in albums the AlbumArtist id3 tag and the other the Artist id3 tag ? It seams so.

If I pick from each track the album dict and make a list of it, deleting the duplicates, I offently end with a list where I got more than once the same album name : so isn’t the album dict. unique for each album ?  
It is, but a very slight difference in the tags ends up with 2 different albums !  
What are the scanned tags wich MUST be identical in each file of an album to have a single Album ?  
Album,AlbumArtist, Musicbrainz Album, … what else ?

As an example, the player Quodlibet relies on the MusicBrainz album ID or labelid to have different albums.Here, we have clearly numerous more tags, it seams. A single uncorrect value, and all is messed up …(?)

Here’s a dummy sample code I wrote. Would it be the right way to use the API ? Any remarks ?  
As I see, i must do the whole part of the tracks filtering myself (?), because there isnt’ a functions who gives me directly all different albums ?

Many questions, I know …  
Thanks for your time.

```auto
import requests
import json

def main():
    url = "http://localhost:6680/mopidy/rpc"
    headers = {'content-type': 'application/json'}
    search = {
        "method": "core.library.search",
        "params": {"query": { "genre":["Jazz"]},"uris" : None, "exact" : False},
        "jsonrpc": "2.0",
        "id": 1,
    }
    response = requests.post(url, data=json.dumps(search), headers=headers).json()
    print json.dumps(response)
    # get all the tracks, is the lengh always 1 ?
    tracks = response["result"][0]["tracks"]
    # get album dict. out for each track
    albums = [track["album"] for track in tracks ]

    unique_album = []
    # delete duplicated albums ....
    for album in albums:
        if album not in unique_album:
            unique_album.append(album)
    # I got offen more than 1 dict. with the same name here, because of slight differences in the tags !
    for album in unique_album:
        print album["name"]

if __name__ == " __main__":
    main()

```

And Have a merry chrismas everybody here !

---

<div class="post-metadata">

**Author:** ![tkem](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/tkem/32/22_2.png) [@tkem](https://discourse.mopidy.com/u/tkem)\
**Post date:** [December 24, 2015, 8:32am UTC](https://discourse.mopidy.com/t/rest-api-questions/1024/4 "2015-12-24T08:32:47Z")

</div>

See here: [http://mopidy.readthedocs.org/en/develop/api/core/?highlight=jinja2#mopidy.core.LibraryController.search](http://mopidy.readthedocs.org/en/develop/api/core/?highlight=jinja2#mopidy.core.LibraryController.search)  
`Return type: list of mopidy.models.SearchResult`  
You’ll basically get one search result from each backend that supports your query. As for search results, these may not only contain tracks, but also artists and/or albums, depending on the capabilities if the backend. You should get yourself acquainted with Mopidy’s data model, then all this will probably make more sense: [http://mopidy.readthedocs.org/en/develop/api/models/](http://mopidy.readthedocs.org/en/develop/api/models/)

---

<div class="post-metadata">

**Author:** ![Klieber\_frederic](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Klieber\_frederic](https://discourse.mopidy.com/u/Klieber_frederic)\
**Post date:** [December 24, 2015, 12:28pm UTC](https://discourse.mopidy.com/t/rest-api-questions/1024/5 "2015-12-24T12:28:19Z")

</div>

Yes, I have seen the [docs.It](http://docs.It) is very well written.

I appears that when i’m doing a request,only tracks are returned, no albums and no artists.  
It’s the same with MusicBox and Moped : when I do a search, the section corresponing to artist and the section album stays empty.  
The respons consits only of a bunch of tracks.

I must have a problem in my setup, and I will try to reinstall everything.  
But the library is correctly scanned and the images are written in the folder I have specified.

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![tkem](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/tkem/32/22_2.png) [@tkem](https://discourse.mopidy.com/u/tkem)\
**Post date:** [December 24, 2015, 12:56pm UTC](https://discourse.mopidy.com/t/rest-api-questions/1024/6 "2015-12-24T12:56:29Z")

</div>

As I said before, whether albums or artists are returned in a search result depends entirely on what backend extensions you have installed. The `local-json` and `local-sqlite` backend will only return tracks as for now. The `internetarchive` backend, for example, will only return albums. The `dleyna` backend may return artists, albums and/or tracks, depending on your DLNA server. And so on.

---

<div class="post-metadata">

**Author:** ![Klieber\_frederic](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@Klieber\_frederic](https://discourse.mopidy.com/u/Klieber_frederic)\
**Post date:** [December 25, 2015, 9:53am UTC](https://discourse.mopidy.com/t/rest-api-questions/1024/7 "2015-12-25T09:53:18Z")

</div>

Ok !  
So for the local-json and local-sqlite I should process things in a similar way that what I have done for now in order to browse per album or artists.  
Or wait for some upcoming functionnalities .  
I think we can close this.

Thanks for your clarification !
