Skip to content

Instantly share code, notes, and snippets.

@froggr
Created July 12, 2024 13:50
Show Gist options
  • Save froggr/cd954556f6d8367d693376b745432309 to your computer and use it in GitHub Desktop.
Save froggr/cd954556f6d8367d693376b745432309 to your computer and use it in GitHub Desktop.
bamboo hr quick submission from console
// Define start and end dates
const start_date = new Date(2024, 6, 8); // month - 1
const end_date = new Date(2024, 6, 8); // month - 1
// your organization prefix for the url:
const company = "initech"
// include your employee id from bamboo
const employee_id = 1146;
// your project id from bamboo
const project_id = 17;
// your task id from bamboo
const task_id = 112;
// csrf from any other request in your console
const csrf_token = "";
// here we go...
function addDays(date, days) {
const result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
function isWeekend(date) {
const day_of_week = date.getDay();
return day_of_week === 0 || day_of_week === 6; // 0 = Sunday, 6 = Saturday
}
let current_date = start_date;
const valid_dates = [];
while (current_date <= end_date) {
if (!isWeekend(current_date)) {
valid_dates.push(new Date(current_date));
}
current_date = addDays(current_date, 1);
}
function submitHours(date) {
const formatted_date = date.toLocaleDateString('en-CA'); // format date as YYYY-MM-DD and not convert utc (to preserve local timezone)
const body = JSON.stringify({
"hours": [{
"id": null,
"dailyEntryId": 1,
"employeeId": employee_id,
"date": formatted_date,
"hours": 8,
"note": "",
"projectId": project_id,
"taskId": 12
}]
});
// ripped from network tab in the dev tools
fetch("https://" + company + ".bamboohr.com/timesheet/hour/entries", {
"headers": {
"accept": "application/json, text/plain, */*",
"accept-language": "en-GB,en;q=0.6",
"content-type": "application/json;charset=UTF-8",
"x-csrf-token": csrf_token
},
"referrer": "https://timelessmedical.bamboohr.com/employees/timesheet/?id=" + employee_id + "&et_id=1885",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": body,
"method": "POST",
"mode": "cors",
"credentials": "include"
}).then(response => {
if (response.ok && response.headers.get("content-type")?.includes("application/json")) {
return response.json();
} else {
console.log('date submitted: ' + formatted_date);
}
})
.then(data => console.log('Success:', data))
.catch((error) => console.error('Error:', error));
}
valid_dates.forEach(submitHours);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment