function getUserID(externalEmail) {
fetch("https:....SOME HOST" + "+'" + externalEmail + "'", {
method:'GET',
headers:{
'Content-Type':'application/json',
'Some Username field':'<username>',
'Some Password field':'<password>'
},
})
.then(function(response) {
return response.json()
}).then(function(json) {
console.log(json.result[0].id)
return json.result[0].id
}).catch(error = > console.log(error));
}
I want to return the id to this function getUserID so i can store it in a variable, something like.
var usersID = getUserID()
I keep getting undefined, i can only see the ID when i console.log(). PS. i specify the userEmail before the function getUserID
If anyone can help that will be much appreciated.
My latest Change....
function delay(){
return new Promise(function(resolve, reject){
var email = "@email.com"
setTimeout(function(){
resolve(fetch("https:....SOME HOST" + "+'" + externalEmail + "'", {
method:'GET',
headers:{
'Content-Type':'application/json',
'Some Username field':'<username>',
'Some Password field':'<password>'
},
}))
} ,1000);
});
}
delay()
.then(function(response){
return response.json()
}).catch(error => console.log(error))