title: Using a POST request to obtain a authorization token and then using POST response in a GET request
body: <p>Requested a spotify access code by using the POST method. Assigned a variable to the response. Then, tried to access the token with a GET method directly following. </p>
  
  <pre><code>   {
          angular.module('app')
              .controller('GameController', function($http){
                  const $ctrl = this;
  
                  $http.post('/access-token').then(function(response){
                      $ctrl.tokenResponse = response.data;
                      $ctrl.myToken = $ctrl.tokenResponse.access_token;
                      console.log(response);
  
                  });
  
                     $http({
                      url: 'https://api.spotify.com/v1/tracks?ids=6rqhFgbbKwnb9MLmUQDhG6',
                      method: 'GET',
                      data: {
                          'Authorization': `Bearer ${$ctrl.myToken}`
                      }
                  }).then(function(response){
                      console.log(response.data);
                      $ctrl.tracks = response.data;
                      console.log($ctrl.tracks);
                  })
  
          });
      };
  </code></pre>
  
  <p>It looks like the GET method is not recognizing the variables in my POST method. My ${$ctrl.myToken} is coming up undefined. "data":{"Authorization":"Bearer undefined"}. But, when I console.log the POST results BEFORE my GET method, it logs the access code just fine.</p>
  
  <p>Not sure how to get my GET method to read the response from my POST method.</p>
  
  <p>All of this code is in my controller.</p>
  
  <p><a href="https://i.stack.imgur.com/6H2MM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6H2MM.png" alt="enter image description here"></a></p>