Fetch and Store Employee Attendance Data Between Two Dates Using API

Hi Bubble community,

I’m working on a project where I need to fetch employee attendance data from an API and store it in a Daily Attendance data type. The structure of my Daily Attendance data type is shown in the image below:

The API I’m using returns data in the following format:

{
“result”: [
{
“attendanceDetails”: {
“2024-08-27”: {
“ShiftStartTime”: “12:00 AM”,
“Status”: “Present”,
“FirstIn_Building”: “-”,
“OverTime”: “02:00”,
“LastOut_Location”: “",
“ShiftName”: “General”,
“FirstIn”: “27-Aug-2024 10:51 AM”,
“FirstIn_Location”: "
”,
“TotalHours”: “10:00”,
“Late_In”: “10:51”,
“WorkingHours”: “08:00”,
“LastOut_Building”: “-”,
“LastOut”: “27-Aug-2024 10:27 PM”,
“Early_Out”: “01:33”,
“ShiftEndTime”: “12:00 AM”
}
},
“employeeDetails”: {
“mail id”: “",
“erecno”: "
”,
“last name”: “",
“first name”: "
”,
“id”: “*****”
}
}
// More employee data here
]
}

Problem Description:

  • I have added two date pickers (Date A and Date B) on my page to allow users to select a start date and an end date.
  • After clicking the Fetch button, I want to fetch all employees’ attendance data between the selected dates using my API and store this data into my Daily Attendance table.

Currently, I’m facing two challenges:

  1. How to store the correct date from the API data: In my current setup, I mistakenly use the current date for storing the attendance, but I need to use the specific date from the API response (e.g., 2024-08-27 for each employee’s attendance on that day).
  2. Storing multiple employee records: I have multiple employees in the API response, and I want to create a new record for each employee in the Daily Attendance data type. The data should include details like:
  • Employee email
  • Attendance status (Present/Absent)
  • Total working hours
  • The correct date (fetched from the API response for each employee).

Here is an example of the expected behavior:

  • Start Date (A): 09/27/2024
  • End Date (B): 09/29/2024
  • The system should fetch the attendance details of all employees between these two dates (09/27/2024, 09/28/2024, and 09/29/2024) and store the corresponding data for each employee for each day.

Current Setup:

I have created two workflows so far:

  1. Fetch Attendance Report:

  2. Create New Daily Attendance Record:

Question:

  • How can I adjust my workflow to store the correct date for each employee’s attendance based on the date in the API response (rather than using the current date)?
  • How do I loop through the API response to create a new record for each employee and store their details in my Daily Attendance table?

Thank you for your help!

can i do it with my Free plan?

@BimaAdhtiyaS_12 @boston85719 @tunacardak @hanan1 @ntabs

Oh it’s kinda hard to explain but have you explored a “do when condition is true”

It’s just an idea never implemented this before, idk if there’s any other method better than this

Basically you create 1 custom state called counter and then X custom state that is a list of the employee per field

You fetch the api, set the custom state for the counter based on the total employee using :count set the custom state of the list based on employee per field

now you called the “do when condition is true” set run this to “every time” don’t forget add condition counter > 0, now you just need to “create a thing” assign the field value to list’employee_name:item#counter’s value and then just -1 the counter value and TADA a LOOP

the minus is prob the workflow cost I think

I didn’t fully understand your explanation. Could you please clarify or explain it in simpler terms?