After adding the advanced Gmail API (under the services menu), something like the following (untested) should work. You may have to play around with it to suit your needs:
function setVacation() {
//example set vacation for May 23 5pm to May 24 6am
var startTime = Math.floor(new Date('5/23/2022 17:00:00').getTime() / 1000)
var endTime = Math.floor(new Date('5/24/2022 06:00:00').getTime() / 1000)
do {
var vacayUpdate = Gmail.users.settings.updateVacation('me', {
"enableAutoReply": true,
"responseSubject": "I'm Out!",
"responseBodyPlainText": "I'm out of the office, please contact XYZ",
// "responseBodyHtml": string, //not used unless you want to build a fancy html email
"restrictToContacts": false, //set as needed
"restrictToDomain": true, //set as needed
"startTime": startTime,
"endTime": endTime
});
console.log(vacayUpdate); //I don't know what this will spit out :)
});