I need to have someone send me a URL with query variables that I want to adjust and pass to a GET api. They don’t need to redirect or anything. Just need to send a GET so the API can log it in the database.
Here is api info
https://ongage.atlassian.net/wiki/spaces/HELP/pages/13795818/API
I need to add headers that have authentication info.
I am connecting one service to another. Neither service I control.
I can do this with non CF JS worker solutions. But for some reason I cannot get this to work for me. I know the header credentials work from using a manual header changer in browser. It works just fine.
Part of the problem is I am having an issue seeing the response. Is there a better way to do this? Am I missing something simple?
addEventListener(‘fetch’, async event => {
await event.respondWith(handleRequest(event.request, event))
})
async function handleRequest(request, event) {
const url = "https://api.ongage.net/api/contacts/add?" + querystring;
let thing = {
method: 'get',
headers: new Headers({
'x_username': '******',
'x_password': ''******',
'x_account_code': ''******'
}),
}
fetch(url, thing)
.then(response => {
if (response.status === 200) {
return response.json();
} else {
throw new Error('Something went wrong on api server!');
}
})
.then(response => {
console.debug(response);
}).catch(error => {
console.error(error);
});
}