My task involves posting timesheet entries for the upcoming month into a system using an API. In order to do this, I require the following:
- User ID
- Assignable ID
- Dates (in the format YYYY-MMM-DD)
- Hours
Initially, I obtained the user_id and assignable_id and stored them in an array. Now, I am attempting to utilize them to make a POST request to the system.
My current challenge lies in including dates in an array and iterating through each day in the array during the POST requests. Any suggestions on how I can accomplish this within the POST loop?
Below is the code for the POST request:
function demo_Code()
{
var user_dt = user_assignments()
for (var i = 0; i < user_dt.length; i++)
{
var data = {
'hours': 0,
// 'date': lastRow[0][2], // This is where I need to change and have next one month datesin an array instead of reading through the sheet
'user_id': user_dt[i].user_id,
'assignable_id': user_dt[i].assignable_id,
};
var payload = JSON.stringify(data);
var options = {
'method': 'POST',
'Content-Type': 'application/json',
'payload': data,
};
var url = 'https://api.10000ft.com/api/v1/users/' + data.user_id + '/time_entries?auth=' + token
var response = UrlFetchApp.fetch(url, options);
}
}