'JavaScript Fetch() Save accessToken, and then pass to another api call

Im new to fetch() and want to save the accessToken from the api call. My code is as follows. My whole process is like one click eventListener, make an api call to save the accessToken then make another api call. I have put the userToken inside another api call, and it seems not working, no reaction at all, i.e., if I put the exact accessToken manually then all g. Btw, the var userToken is a global variable.

var resJson;
fetch("https://...", requestOptions).then(response => 
response.json()).then(data => resJson = data);
userToken = JSON.stringify(resJson.token.accessToken);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source