Extract value from response body and use it in the subsequent post request

Hi,

I am trying to write api test , where I am extracting a token from the first call and use it in the second post request, the insight example doesn’t seem to be working for me.

1 Like

Hi, @basma.asaad: Usually this happens because you are not making the second request within the callback function of the first one. The code should look like this:

$http.post(uri, data,
  // Callback
  function (err, response, body) {
    // Extract response data
    var data = JSON.parse(body);
    // Make next call
    $http.post(uri, data,
      // Callback
      function (err, response, body) {
        // Handle response of second call
      });
  });
4 Likes

Thank you @philweber