Search code examples
node.jssoundcloudcdnnpm-request

SoundCloud API: same call, different response between curl and NodeJS


I have a problem calling the SoundCloud API: for the same API call from the same server I get different results between doing a CURL request and NodeJs. The following two calls have been made within 2 seconds one from the other.

Call from our server "SiaMusic": curl http://api.soundcloud.com/users/3789802?client_id=MY_CLIENT_ID

Response: {"id":3789802,"kind":"user","permalink":"siamusic","username":"SiaMusic","last_modified":"2016/03/27 21:00:51 +0000","uri":"https://api.soundcloud.com/users/3789802","permalink_url":"http://soundcloud.com/siamusic","avatar_url":"https://i1.sndcdn.com/avatars-000073011508-o3ui3y-large.jpg","country":null,"first_name":"","last_name":"","full_name":"","description":"","city":"","discogs_name":null,"myspace_name":null,"website":"http://siamusic.net/","website_title":"","track_count":204,"playlist_count":23,"online":false,"plan":"Pro Plus","public_favorites_count":1,"subscriptions":[{"product":{"id":"creator-pro-unlimited","name":"Pro Unlimited"}}],"followers_count":137277,"followings_count":0}

Call from NodeJs using "request" module:

var options = {
  method: 'GET',
  url: 'http://api.soundcloud.com/users/3789802',
  qs: {client_id: 'MY_CLIENT_ID' },
  json: true
};
request(options, function(err, response, body) {
    //handle error, if body
    console.log(body);
}

Response: body: { id: 3789802, kind: 'user', permalink: 'siamusic', username: 'SiaMusic', last_modified: '2016/03/27 21:00:51 +0000', uri: 'https://api.soundcloud.com/users/3789802', permalink_url: 'http://soundcloud.com/siamusic', avatar_url: 'https://i1.sndcdn.com/avatars-000073011508-o3ui3y-large.jpg', country: null, first_name: '', last_name: '', full_name: '', description: '', city: '', discogs_name: null, myspace_name: null, website: 'http://siamusic.net/', website_title: '', track_count: 204, playlist_count: 23, online: false, plan: 'Pro Plus', public_favorites_count: 1, subscriptions: [ [Object] ], followers_count: 136692, followings_count: 0 }}

As you can see from the JSON the "followers_count" differs a lot and also happens (for NodeJs calls) that I get the same results across 5 to 30 days. Are the API served by a CDN?


Solution

  • As said in the comments of my original question the problem is solved by adding a timestamp field in the QueryString of the API call. That way the request will always be different and you'll always obtain the most updated value.

    Thanks to @JacopoBrovida for the tips!