14

I'm using Javascript to create a web app with Soundcloud's API for my portfolio. At my current stage I need to be able to create a new set (aka playlist). I was using the sample code from Soundcloud's docs:

SC.connect(function() {
  var tracks = [22448500, 21928809].map(function(id) { return { id: id } });
  SC.post('/playlists', {
    playlist: { title: 'My Playlist', tracks: tracks }
  });
}); 

But I'm getting a 422 error:

Unprocessable Entity - The request looks alright, but one or more of the parameters looks a little screwy. It's possible that you sent data in the wrong format (e.g. an array where we expected a string).

But it does not look like anything's missing.

3
  • maybe because 21928809 is not a valid/public track, while 22448500 is ok ?
    – CapelliC
    Jul 13, 2015 at 7:40
  • you have authed the user in advance? afaik you need to use PUT instead of POST according to the docs. you may wanna have a look in that answer, even if its php: stackoverflow.com/questions/29156861/…
    – hwsw
    Jul 13, 2015 at 8:28
  • I did authorize the the user as my first step after initialization. Other portions of my code work, but currently stuck at this point. Will continue digging. Jul 14, 2015 at 4:55

1 Answer 1

6
+50

The call to the SoundCloud API requires a callback function in addition to the playlist title and tracks. Your code should look like this:

SC.connect(function() {
  var tracks = [22448500, 21928809].map(function(id) { return { id: id } });
  SC.post('/playlists', {
    playlist: { title: 'My Playlist', tracks: tracks }, function(response){
      console.log(response)
    }
  });
});

Their example is, unfortunately, wrong.

1
  • Thanks Cory that did the trick; I knew there was something off in their docs. Also I figured out the source of the 422 I was getting: I had a typo and left out the "/" from the endpoint path 'playlist,' thus it would resolve to "api.soundcloud.comme.." or "api.soundcloud.complay..." Two bugs killed in one sitting, excellent. Jul 17, 2015 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.