title: How to specify the country code for the Spotify Web API in Android?
body: <p>In my android application, I am trying to get an artist's top ten tracks. I'm using a <a href="https://github.com/kaaes/spotify-web-api-android/" rel="nofollow">wrapper</a> for the Spotify Web API. To get the artist's top ten tracks you have to provide the <code>getArtistTopTrack(id)</code> method with the artist's <code>id</code>. </p>
  
  <p>Here's my code that is meant to do that:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_top_ten);
  
      Intent intent = getIntent();
  
      String artistID = "";
      artistID = intent.getExtras().getString("ID");
  
      FetchTopTenTracksTask topTenTracksTask = new FetchTopTenTracksTask();
      topTenTracksTask.execute(artistID);
  }
  
  private class FetchTopTenTracksTask extends AsyncTask&lt;String, Void, Tracks&gt; {
  
      @Override
      protected Tracks doInBackground(String... params) {
          SpotifyApi api = new SpotifyApi();
          SpotifyService spotify = api.getService();
  
          return spotify.getArtistTopTrack(params[0]);
      }
  </code></pre>
  
  <p>The error that I am getting is </p>
  
  <pre class="lang-none prettyprint-override"><code>E/AndroidRuntime(2882): FATAL EXCEPTION: AsyncTask #2
  E/AndroidRuntime(2882): java.lang.RuntimeException: An error occured while executing doInBackground()
  </code></pre>
  
  <p>and it was caused by <code>doInBackground</code>. My thoughts are the bad request is caused by this line of code because I need to specify a country code for the search (the API requires this) but I don't know how to.</p>
  
  <pre><code>return spotify.getArtistTopTrack(params[0]);
  </code></pre>
  
  <p>The correct endpoint for getting an artist's top tracks is</p>
  
  <pre class="lang-none prettyprint-override"><code>GET https://api.spotify.com/v1/artists/{the artists id}/top-tracks?country={ISO 3166-1 alpha 2 country code}
  </code></pre>
  
  <p>But when I checked the LogCat to see what endpoint it was using it turned to be an incorrect one</p>
  
  <pre class="lang-none prettyprint-override"><code>D/Retrofit(2882): &lt;--- HTTP 400 https://api.spotify.com/v1/artists/{the artist id}%3Fcountry%3DIE/top-tracks (59ms)
  </code></pre>
  
  <p>As you can see, the country code which is "IE" is appended to the artist <code>id</code>, like this: <code>"%3Fcountry%3DIE"</code>. This is what is causing the error, because the request could not be understood by the server, due to malformed syntax.</p>
  
  <p>Can someone show me how I can append <code>"?country={country code}"</code> to the endpoint, instead of having it right after the artist id?</p>