I am making a GET api call to a url in Drupal. I want to obtain the PromiseResult and place it in a variable to be used in another api call.
Here is my code:
fetch('/session/token')
.then(res => res.text())
.then(text => console.log(text))
Basically, this code goes to the /session/token url and it retrieves a token to be used in the X-CSRF-token
header for another api call.
This is what the result of the console.log(text)
looks like:
<This is the actual token which is a string of characters>
How would I put the value of this token in a variable?