I am pretty new to JavaScript and I'm trying to embed into my code a fetch GET request. I have a GET request that works pretty well if sent with Postman. I translated it with the Code Snippet tool provided by Postman and wrote my function:
function fetchGET() {
var value = "";
var myHeaders = new Headers();
myHeaders.append("Cookie", "---MyCookie---");
var raw = "";
var requestOptions = {
method: 'GET',
headers: myHeaders,
credentials: 'include',
body: raw,
redirect: 'follow'
};
fetch("---MyURL---", requestOptions)
.then(response => value = response.text())
.then(result => value = result)
.catch(value = "ERROR");
return value;
}
the only value I get, though, is "ERROR".
If I copy/paste the function into the Chrome console this is the error message I get:
I tried to remove the body but nothing changes. What am I doing wrong? Thank you all!