Soundcloud PUT API returning 401 Soundcloud PUT API returning 401 curl curl

Soundcloud PUT API returning 401


If you want to pass your token, simply append "&oauth_token=" + TOKEN_VALUE

https://api.soundcloud.com/tracks/11111111?client_id=12345666666&oauth_token=YOUR_TOKEN

Edited to add example code

Here is an example of PUT using Curl & with PHP for soundcloud auth token. This code is from a working soundcloud project.

$data = array(  'code' => $token,  'client_id' => $this->getClientId(false), // your client ID  'client_secret' => $this->getClientSecret(), // your client secret  'redirect_uri' => $this->getCallback(), // callback URL  'grant_type' => 'authorization_code');$url = "https://api.soundcloud.com/oauth2/token";try {  $ch = curl_init();  // set options  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  curl_setopt($ch, CURLOPT_URL, $url);  curl_setopt($ch, CURLOPT_HEADER, true);  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  curl_setopt($ch, CURLOPT_POST, true);  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  curl_setopt($ch, CURLOPT_VERBOSE, 1);  $response = curl_exec($ch);  $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);  $header = substr($response, 0, $header_size);  $body = substr($response, $header_size);        // read / process result  curl_close($ch);} catch(Exception  $e) {  // error handling...}


This may work. Try turning off various CURL options. In my case I had PUT working under PHP5.5 but after migrating to new server with PHP7 the POST operation would fail until I set CURLOPT_SAFE_UPLOAD to false for soundcloud POST operations (file uploads); however after making this change to all my curl inits, my PUT operations failed because they also had safeupload set to false, so I removed this setting from my PUT operations and the PUT operations started working.

In short, try turning off SAFE UPLOAD option for your PUT operations.

More info about this curl option on this post.