0

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?

Shane
  • 111
  • 7
  • 1
    I think this https://stackoverflow.com/questions/45018338/javascript-fetch-api-how-to-save-output-to-variable-as-an-object-not-the-prom will answer your question. – Diamoniner12345 Dec 15 '22 at 18:39

0 Answers0