window.postWithHeader = function(url, method, headerKey, headerValue) { fetch(url, { method: method, headers: { [headerKey] : headerValue } }).then(res => { if (res.redirected) { window.location.href = res.url; } }); }; window.fetchWithHeaderAndReturnUrl = async function(url, method, headerKey, headerValue) { const response = await fetch(url, { method: method, headers: { [headerKey]: headerValue } }); const data = await response.json(); return data.url; };