I am trying to integrate with the QuickBooks Time API, specifically with time off requests. The API docs are found here: https://tsheetsteam.github.io/api_docs/?java#retrieve-time-off-requests
Here is the code I have in Zapier. Note, I had to put a t] around the results to remove the “Results must be an array, got: object,” error.
const options = {
url: 'https://rest.tsheets.com/api/v1/time_off_requests',
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${bundle.authData.access_token}`
},
params: {
}
}
return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;
// You can do any parsing you need for results here before returning them
return results];
});
Here is a typical output according to the API docs. Note this is sample data:
{
"results": {
"time_off_requests": {
"1546922": {
"id": 1546922,
"user_id": 423,
"time_off_request_notes": _96024],
"time_off_request_entries": n11374, 11375],
"status": "pending",
"active": true,
"created": "2018-11-11T10:56:15-06:00",
"last_modified": "2018-11-11T10:56:15-06:00"
},
"1547432": {
"id": 1547432,
"user_id": 467,
"time_off_request_notes": _100021],
"time_off_request_entries": n11564],
"status": "pending",
"active": true,
"created": "2018-11-12T10:05:02-06:00",
"last_modified": "2018-11-12T10:05:02-06:00"
}
}
},
"more": false,
"supplemental_data": {
"users": {
"423": {
"id": 423,
"first_name": "Sean",
"last_name": "Evans",
"group_id": 34,
"active": true,
"employee_number": 4,
"salaried": false,
"exempt": false,
"username": "sevans",
"email": "sevans@hotones.com",
"payroll_id": 4,
"hire_date": "2017-04-27",
"term_date": "0000-00-00",
"job_title": "",
"gender": "",
"last_modified": "2017-09-21T15:52:00-06:00",
"last_active": "2018-11-12T11:45:15-06:00",
"created": "2017-04-27T07:23:44-06:00",
"mobile_number": ""
},
"467": {
"id": 467,
"first_name": "Guy",
"last_name": "Fieri",
"group_id": 34,
"active": true,
"employee_number": 5,
"salaried": false,
"exempt": false,
"username": "gfieri",
"email": "gfieri@foodnetwork.com",
"payroll_id": 5,
"hire_date": "2017-07-12",
"term_date": "0000-00-00",
"job_title": "",
"gender": "",
"last_modified": "2017-09-21T15:02:00-06:00",
"last_active": "2018-11-12T13:12:01-06:00",
"created": "2017-07-12T08:05:22-06:00",
"mobile_number": ""
}
},
"time_off_request_notes" : {
"96024": {
"id": 96024,
"time_off_request_id": 1546922,
"user_id": 423,
"active": true,
"note": "Taking a four day weekend to go on vacation.",
"created": "2018-11-11T10:56:15-06:00",
"last_modified": "2018-11-11T10:56:15-06:00"
},
"100021": {
"id": 100021,
"time_off_request_id": 1547432,
"user_id": 467,
"active": true,
"note": "It's my birthday!",
"created": "2018-11-12T10:05:02-06:00",
"last_modified": "2018-11-12T10:05:02-06:00"
}
},
"time_off_request_entries": {
"11374": {
"id": 11374,
"time_off_request_id": 1546922,
"status": "pending",
"approver_user_id": 0,
"date": "2018-11-15",
"entry_method": "manual",
"duration": 28800,
"start_time": "2018-11-15T00:00:00-07:00",
"end_time": "2018-11-15T23:59:59-07:00",
"tz_string": "America/Denver",
"jobcode_id": 1345687,
"user_id": 423,
"approved_timesheet_id": 0,
"active": true,
"created": "2018-11-11T10:56:15-06:00",
"last_modified": "2018-11-11T10:56:15-06:00"
},
"11375": {
"id": 11375,
"time_off_request_id": 1546922,
"status": "pending",
"approver_user_id": 0,
"date": "2018-11-16",
"entry_method": "manual",
"duration": 28800,
"start_time": "2018-11-16T00:00:00-07:00",
"end_time": "2018-11-16T23:59:59-07:00",
"tz_string": "America/Denver",
"jobcode_id": 1345687,
"user_id": 423,
"approved_timesheet_id": 0,
"active": true,
"created": "2018-11-11T10:56:15-06:00",
"last_modified": "2018-11-11T10:56:15-06:00"
},
"11564": {
"id": 11564,
"time_off_request_id": 1547432,
"status": "pending",
"approver_user_id": 0,
"date": "2018-01-22",
"entry_method": "manual",
"duration": 28800,
"start_time": "",
"end_time": "",
"jobcode_id": 1345645,
"user_id": 467,
"approved_timesheet_id": 0,
"active": true,
"created": "2018-11-12T10:05:02-06:00",
"last_modified": "2018-11-12T10:05:02-06:00"
}
}
}
}
The issue I am seeing is that it looks like the ID is nested, and I have no clue how to parse this out? I am a fairly new coder, how would I remove
"time_off_requests": {
and the
"1546922": {
to get down to the
"id": 1546922,
level?