Closed rublev closed 7 years ago
Does anybody know how to do this in isomorphic-fetch? Every library but iso-fetch is broken for me when using webpack2 and I can't seem to get this working at all.
In fetch, to do HTTP Basic auth, you have to set the Authorization
header yourself. This Stack Overflow answer explains how to do it.
Welp, btoa
did it. I had exactly this code before but without using btoa, so I must have done something wrong with b64, overlooked it, and then entered a rabbithole.
const response = await fetch('https://awd.zendesk.com/api/v2/help_center/articles.json', {
method: 'GET',
headers: {
'Authorization': 'Basic '+btoa('user@site.com/token:token'),
'Content-Type': 'application/x-www-form-urlencoded'
},
}).then(res => {
console.log(res);
return res.json();
}).then(res => {
console.log(res)
})
Christ I can't believe it took me this long, I need to find a new field of work.
I have the following cURL which returns data just fine. I was able to get it working with the
request
library but I have no idea how to convert this call to a fetch call.