Discussions

Ask a Question
Back to All

post request from app script

Hi team!

I have a code in JS - fetch library, i tried to run it in the app script of google sheets, but it fails and gives me an error : ReferenceError: URLSearchParams is not defined

here is my code:

function Humanity() {
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
start_time: '04:00',
end_time: '05:00',
start_date: 'Oct 14, 2022',
end_date: 'Oct 14, 2022',
schedule: '2951815'
})
};

fetch('https://www.humanity.com/api/v2/shifts?access_token=xxx', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
}

how to make it work from app script?