I would like to post some timesheet entries for the next month into a system via API. For this I need
- user_id
- assignable_id
- Dates (Format YYYY-MMM-DD)
- Hours
First I downloaded user_id and assignable_id and stored them in an array and now am trying to use them to send a POST request to the system.
My challenge is, I am having trouble getting dates into an array and loop through each day in the array whenever the POST requests are made. Any pointers on how I can achieve this inside the POST loop?
Here is the code for 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);
}
}
question from:
https://stackoverflow.com/questions/66052441/javascript-gas-how-can-i-loop-through-dates-in-a-post-request 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…