# Unable to create a playlist from a podcast URI in mopidy.js

**URL:** <https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737>\
**Category:** Misc\
**Created:** [May 19, 2015, 7:59pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737 "2015-05-19T19:59:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fluppe2root](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/fluppe2root/32/185_2.png) [@Fluppe2root](https://discourse.mopidy.com/u/Fluppe2root)\
**Post date:** [May 19, 2015, 7:59pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/1 "2015-05-19T19:59:41Z")

</div>

Hi guys!

I’m working on a internet radio (spotify/podcasts) on a raspberry pi in an Ikea hack, and absolutely loving Mopidy so far! However, I run into the following problem: when trying to create a playlist based on a podcast URI, no playlist seems to be created. More specifically, the following code returns the console error: [TypeError: Cannot read property ‘name’ of null]

```
var Mopidy = require("mopidy");
var mopidy = new Mopidy({
  webSocketUrl: "ws://localhost:6680/mopidy/ws",
  callingConvention: "by-position-only"
});

var init = function() {
  mopidy.playlists.create("Podcast Playlist", "http://www.npr.org/rss/podcast.php?id=510019").then(function(playlist) {
    console.log(playlist.name);
  })
  .catch(console.error.bind(console))
  .done();
};

mopidy.on("state:online", init);

```

I tried different variations of the podcast url (e.g., podcast:// or podcast+http:// instead of http://, as mentioned on [https://github.com/tkem/mopidy-podcast/issues/7](https://github.com/tkem/mopidy-podcast/issues/7)) but got the same error. Probably, I’m missing something obvious 🙂 but I’m not finding any clues in the forums or on github. Any clues or pointers are greatly appreciated!

---

<div class="post-metadata">

**Author:** ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)\
**Post date:** [May 19, 2015, 8:14pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/2 "2015-05-19T20:14:08Z")

</div>

I suspect this is the same issue as was fixed in [https://github.com/mopidy/mopidy/pull/1165](https://github.com/mopidy/mopidy/pull/1165), which was released in Mopidy 1.0.5 a few mintues ago. Can you retry with that version?

---

<div class="post-metadata">

**Author:** ![Fluppe2root](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/fluppe2root/32/185_2.png) [@Fluppe2root](https://discourse.mopidy.com/u/Fluppe2root)\
**Post date:** [May 19, 2015, 9:27pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/3 "2015-05-19T21:27:33Z")

</div>

Thanks a lot, @jodal ! Indeed, after the upgrade to 1.0.5, the javascript code displayed the name of the playlist correctly 🙂

However, I expected that the podcast episodes would then be added as tracks for that playlist. Currently, no tracks seem to be present in the playlist: the musicbox web client also shows the playlist, but no tracks. Is this by design? Anyway, I’ll try to look further into it tomorrow.

---

<div class="post-metadata">

**Author:** ![adamcik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/adamcik/32/5_2.png) [@adamcik](https://discourse.mopidy.com/u/adamcik)\
**Post date:** [May 19, 2015, 9:48pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/4 "2015-05-19T21:48:28Z")

</div>

The API is a bit funny due to well legacy reasons. You have to `create` a new playlist model instance, then you can replace that `tracks` key with a new list of tracks. These also need to be valid models, so run the URIs through `library.lookup` to get them converted. Then once that is done you can call `save` on your modified playlist instance.

Longer term we really really hope to kill this form of the API, as it isn’t exactly nice to work with or explain.

---

<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:** [May 20, 2015, 11:12am UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/5 "2015-05-20T11:12:29Z")

</div>

Since a few lines of code may explain this better, @Fluppe2root may want to have a look at

[https://github.com/tkem/mopidy-mobile/blob/master/www/js/tracklist.js#L215](https://github.com/tkem/mopidy-mobile/blob/master/www/js/tracklist.js#L215)

which saves the current tracklist as a playlist. Note also that you don’t have to do a `library.lookup` necessarily; you can use any JS object that looks like a proper `Track` model to Mopidy, i.e. has `uri`, `name` and ` __model__ ` fields; see

[https://github.com/tkem/mopidy-mobile/blob/master/www/js/playlists.js#L269](https://github.com/tkem/mopidy-mobile/blob/master/www/js/playlists.js#L269)

for an example.

---

<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:** [May 20, 2015, 3:06pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/6 "2015-05-20T15:06:44Z")

</div>

Which reminds me, that I always wanted to suggest for Mopidy.js to provide some way to create proper models in a less “hackish” way. Like

`Mopidy.track({uri="foo", name="bar", ...})`

---

<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:** [May 20, 2015, 3:25pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/7 "2015-05-20T15:25:19Z")

</div>

I thought that one benefit of the newer Ref based APIs was the that we wouldn’t have to worry about creating models any more.

---

<div class="post-metadata">

**Author:** ![Fluppe2root](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/fluppe2root/32/185_2.png) [@Fluppe2root](https://discourse.mopidy.com/u/Fluppe2root)\
**Post date:** [May 20, 2015, 7:47pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/8 "2015-05-20T19:47:19Z")

</div>

Thanks @adamcik and @tkem, I’m able to add tracks now! I’ll keep on tinkering, and hope to show you another finished Mopidy project soon!

---

<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:** [May 20, 2015, 8:38pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/9 "2015-05-20T20:38:35Z")

</div>

@kingosticks: But a `Ref` _is_ a model 😉

---

<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:** [May 20, 2015, 8:42pm UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/10 "2015-05-20T20:42:08Z")

</div>

True, but even I can’t get it wrong!

---

<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:** [May 21, 2015, 5:45am UTC](https://discourse.mopidy.com/t/unable-to-create-a-playlist-from-a-podcast-uri-in-mopidy-js/737/11 "2015-05-21T05:45:20Z")

</div>

See also [https://github.com/mopidy/mopidy.js/issues/7](https://github.com/mopidy/mopidy.js/issues/7)
