My question:
My goal is to trigger a POST request for TokenRefresh and get the RefreshedToken Info from the request response and store it in a Collection variable.
Each request should then be able to use the updated Collection variable for its authentification.
Details (like screenshots):
pm.sendRequest({
url: “URL”,
method: “POST”,
header: {
“Content-Type”: “application/x-www-form-urlencoded”
},
body: {
mode: “urlencoded”,
urlencoded:
[
{key: “client_id”,value: “XXX”},
{key: “grant_type”,value: “refresh_token”},
{key: “refresh_token”,value: “ACCESSTOKEN”},
]
}
});
//Now I want to search the response for access_token and save it in the Collection variable
let jsonResponse = pm.response.json();
console.log(jsonResponse);
pm.collectionVariables.set(“CollRefToken”, jsonResponse.access_token)
How I found the problem:
When I send a request in the Collection, the Auth POST request is correctly sent, but something is wrong in my setting the Collection variable:
“TypeError: Cannot read properties of undefined (reading ‘json’)”
There was an error in evaluating the Pre-request Script:Error: Cannot read properties of undefined (reading ‘json’)