I was able to resolve this with the following code:
<div id="twitch-embed"></div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://embed.twitch.tv/embed/v1.js"></script>
<script>
var channel_name = "";
var client_id = ""
fetch(
'https://api.twitch.tv/helix/streams?user_login=' + channel_name,
{
method: 'GET',
headers: {
'Accept': 'application/json',
'Client-ID': client_id
}
}
).then(response => response.json()
).then(response => {
if (response.data[0] != undefined){
new Twitch.Embed("twitch-embed", {
width: 1280,
height: 500,
channel: channel_name,
theme: "dark"
});
};
}).catch(err => {
console.log(err);
});
</script>