Mock an API request body to use data from the response of another API. This can be done by aggregating the response body in $sharedState
.
Note:
$sharedState
is only available in extension version >24.8.13
and desktop app >v1.7.1
Steps to aggregate data in modify response rule
-
Create a new modify response rule
-
Select dynamic javascript modification
-
Write javascript code to aggregate the data from response body in
$sharedState
function modifyResponse(args) { const {method, url, response, responseType, requestHeaders, requestData, responseJSON} = args; // Change response below depending upon request attributes received in args const productList=responseJSON.products; const currency=responseJSON.currency; // Store data in $sharedState $sharedState.productList=productList; $sharedState.currency=currency; return response; }
Step to use the aggregated data in modify request body
-
Create a new modify request body rule
-
Select dynamic javascript modification
-
Write javascript code to aggregate the data from response body in
$sharedState
function modifyRequestBody(args) { const { method, url, body, bodyAsJson } = args; //Retreive data from $sharedState const products = $sharedState.productList; const currency = $sharedState.currency; return { ...bodyAsJson, products, currency } }