I'm trying to build a HTML, CSS, JS website and want to incorporate an API and use the response further in my website.
I've managed to make this API part work but I'm stuck with the final part.
What I've Achieved
- Executing a JS function using FETCH that makes a POST Call with Auth Headers
- Getting the response to show up inside my Chrome Developer Console.
What I'm trying to achieve
- Use the Response (Web URL) that is being received by the POST API Call inside my website as a variable. So when the user hits a button this response (URL) opens up in a new tab.
In simple terms, I want the make use of the web url that shows up in the Chrome Console.
Here is the code I'm using
function initiateIDV(){
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic xxxxxxxxxxxxx");
var raw = JSON.stringify({
"customerInternalReference": "Will's App",
},
"userReference": "test-app",
"tokenLifetime": "10m"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://[hidden]/api/v1/accounts", requestOptions)
.then(response => response.json())
.then(result => console.log(result.web.href))
.catch(error => console.log('error', error));
}