0

I have some problems with the soundcloudapi and I hope someone can help me. All GET Methods work perfectly, but now I want to create a new playlist on SoundCloud and I always receive response 422 with message:

"Unprocessable Entity"

This is my current API execution method:

private T Execute<T>(Uri url, HttpMethod method = null, object bodyParams = null) 
        where T: class
    {
        var uri = url.AddParameter("oauth_token", Uri.EscapeDataString(tokenKey)).AddParameter("client_id", ((SoundCloudAuthenticationOptions)AuthenticationOptions).ClientId);
        var httpRequestMessage = new HttpRequestMessage(method ?? HttpMethod.Get, uri);

        if (bodyParams != null)
        {
            httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(bodyParams));
        }
        
        HttpResponseMessage response = httpClient.SendAsync(httpRequestMessage).Result;
        //  response.EnsureSuccessStatusCode();
        var json = response.Content.ReadAsStringAsync().Result;

        var jObject = JObject.Parse(json);
        if (typeof (T) == typeof (JObject))
            return jObject as T;
        return jObject.ToObject<T>();
    }

And for creating a playlist I call it like

Execute<JObject>(apiUrl.Append("playlists"), HttpMethod.Post, new { playlist = new { title = name, sharing = "private", tracks = new string[0] } })
1
  • About http error 422 For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions. Could it be that your tracks list is empty? Commented Sep 18, 2015 at 8:44

1 Answer 1

0

I'm not 100% sure what the issue is, but I've used this library in the past for the SoundCloud API (the library doesnt come without its issues)

https://github.com/Haythem/SoundCloud.NET

You could take a look there, and see how they do it.

On the other hand, I was just playing around with the SoundCloud website, and tested creating a few playlists using chrome developer tools - i've found that creating a playlist with no tracks is not allowed.

You may simply want to try to execute your command with a non-empty tracks list.

2
  • Thank you very much i will check it. Commented Sep 18, 2015 at 9:20
  • Thanks i have found a different.. If i add the parameters to the url and not to the body it will work. Thanks a lot. Commented Sep 18, 2015 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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