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.
Our API gives you the ability to upload, manage and share tracks. Your app can take an audio file and upload it to a user's SoundCloud account. You can also manage metadata (including tags) or add the track to playlists.
To access the SoundCloud® API, you will first need to register your app at https://soundcloud.com/you/apps using your SoundCloud® account. When you've done that, we'll issue you with a client ID and client secret. Your client ID is required for all calls to the SoundCloud® API.
You need to get your client_id and client_secret by registering your app here. After you have obtained that, you can start using the API. Basically, most of the calls will look like this one: final SoundCloud api = new SoundCloud.
The SDKs will make it easier to access the SoundCloud API on your framework of choice. We officially provide and support only JavaScript. All other SDKs (Ruby, Python) are supported by third-party developers.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With