Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(bamboohr): add time tracking, holiday and custom field tables (#113238)

Tom Owers77d4628498ff
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index d059fb72fe60..729ccc049443 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -707,7 +707,7 @@ Note: The developer hub serves a Swagger UI whose visible initializer points at
## BambooHR — **thin**
-Today (22): `applicant_statuses`, `application_details`, `applications`, `ats_locations`, `employee_compensation`, `employee_employment_status`, `employee_goal_comments`, `employee_goals`, `employee_job_info`, `employee_time_off_balances`, `employee_time_off_policies`, `employees`, `job_openings`, `locations`, `meta_fields`, `meta_lists`, `meta_users`, `time_off_policies`, `time_off_requests`, `time_off_types`, `timesheet_entries`, `whos_out`
+Today (28): `applicant_statuses`, `application_details`, `applications`, `archived_custom_fields`, `ats_locations`, `clock_entries`, `custom_fields`, `employee_compensation`, `employee_employment_status`, `employee_goal_comments`, `employee_goals`, `employee_job_info`, `employee_time_off_balances`, `employee_time_off_policies`, `employees`, `holidays`, `hour_entries`, `job_openings`, `locations`, `meta_fields`, `meta_lists`, `meta_users`, `time_off_policies`, `time_off_requests`, `time_off_types`, `timesheet_entries`, `timesheets`, `whos_out`
Diffed against: <https://documentation.bamboohr.com/sitemap.xml>
@@ -723,6 +723,11 @@ Diffed against: <https://documentation.bamboohr.com/sitemap.xml>
- [ ] `GET company benefits, employee benefits, benefit coverages, deduction types` — benefits enrollment and its lookup tables - a major HRIS reporting area (medium)
- [ ] `GET list datasets + get data from dataset (Workforce Analytics)` — the vendor's own analytics datasets, discoverable at sync time (medium)
- [ ] `GET list reports + get report by id / get company report` — saved company reports, the shape most BambooHR admins already think in (medium)
+- [x] `GET /api/v1/time-tracking/timesheets` — pay-period timesheets with hour totals and approval state, from the newer time-tracking API (high)
+- [x] `GET /api/v1/time-tracking/hour-entries` — hour entries per timesheet, from the newer time-tracking API (high)
+- [x] `GET /api/v1/time-tracking/clock-entries` — clock-in/clock-out entries per timesheet, from the newer time-tracking API (high)
+- [x] `GET /api/v1/holidays` — company holidays with audience and pay treatment; before this they only appeared as rows inside whos_out (medium)
+- [x] `GET /api/v1/hris/custom-fields (plus /archived)` — custom field and custom table definitions, active and archived (medium)
Note: documentation.bamboohr.com is a ReadMe site with no public OpenAPI download (the /reference slug in the source config 404s), but its sitemap enumerates all 312 reference pages, which is what I diffed against. Six tables against roughly 130 GET endpoints spanning employees, time off, time tracking, scheduling, benefits, goals, training, ATS, compensation benchmarks and reports. Also below the cut: employee dependents, scheduling shifts/schedules, compensation benchmarks, bank holidays, break policies.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/bamboohr.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/bamboohr.py
index b7092b655a10..a4ed66c8d159 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/bamboohr.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/bamboohr.py
@@ -150,12 +150,13 @@ def _page_from_url(url: Any) -> int | None:
return None
-class BambooHRApplicationsPaginator(BasePaginator):
- """Walks the ATS applications envelope (``paginationComplete`` plus ``nextPageUrl``).
+class BambooHRPageLinksPaginator(BasePaginator):
+ """Walks a page-numbered endpoint by the page number in the next-page link of each response.
- ``nextPageUrl`` is read only for the page number it carries, never followed: BambooHR builds
- it against the company's own domain while we call the same API through the gateway host the
- API key was issued for, so following it verbatim would leave that host.
+ The link is read only for the page number it carries, never followed: BambooHR builds it
+ against the company's own domain while we call the same API through the gateway host the
+ API key was issued for, so following it verbatim would leave that host. Reading the number
+ from the link also keeps the walk correct whichever page number the endpoint counts from.
"""
def __init__(self, page_param: str = "page") -> None:
@@ -174,17 +175,23 @@ class BambooHRApplicationsPaginator(BasePaginator):
def init_request(self, request: Request) -> None:
self._apply(request)
+ def _next_page_url(self, payload: dict[str, Any]) -> Any:
+ links = payload.get("_links")
+ next_link = links.get("next") if isinstance(links, dict) else None
+ return next_link.get("href") if isinstance(next_link, dict) else None
+
def update_state(self, response: Response, data: Optional[list[Any]] = None) -> None:
try:
payload = response.json()
except Exception:
payload = None
- if not isinstance(payload, dict) or payload.get("paginationComplete") or not data:
+ if not isinstance(payload, dict) or not data:
self._has_next_page = False
return
- next_page = _page_from_url(payload.get("nextPageUrl"))
+ next_page_url = self._next_page_url(payload)
+ next_page = _page_from_url(next_page_url)
if next_page is None:
- if not payload.get("nextPageUrl"):
+ if not next_page_url:
self._has_next_page = False
return
# A next link we cannot read a page number out of still means more rows, so step
@@ -197,6 +204,18 @@ class BambooHRApplicationsPaginator(BasePaginator):
def update_request(self, request: Request) -> None:
self._apply(request)
+ def __str__(self) -> str:
+ return "BambooHRPageLinksPaginator(_links.next.href)"
+
+
+class BambooHRApplicationsPaginator(BambooHRPageLinksPaginator):
+ """Walks the ATS applications envelope (``paginationComplete`` plus ``nextPageUrl``)."""
+
+ def _next_page_url(self, payload: dict[str, Any]) -> Any:
+ if payload.get("paginationComplete"):
+ return None
+ return payload.get("nextPageUrl")
+
def __str__(self) -> str:
return "BambooHRApplicationsPaginator(paginationComplete|nextPageUrl)"
@@ -208,6 +227,8 @@ def _paginator_for(config: BambooHREndpointConfig) -> BasePaginator:
return PageNumberPaginator(base_page=FIRST_PAGE_NUMBER, stop_after_empty_page=True)
if config.pagination == "ats_applications":
return BambooHRApplicationsPaginator()
+ if config.pagination == "page_links":
+ return BambooHRPageLinksPaginator()
return BambooHRPaginator()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/canonical_descriptions.py
index 0bc850e472e1..22c84094bccf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/canonical_descriptions.py
@@ -297,4 +297,111 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"lastLogin": "Time at which the user last logged in.",
},
},
+ "timesheets": {
+ "description": "An employee's timesheet for one pay period, with its hour totals and approval state.",
+ "docs_url": "https://documentation.bamboohr.com/reference/list-timesheets",
+ "columns": {
+ "id": "Unique identifier for the timesheet.",
+ "employeeId": "ID of the employee the timesheet belongs to.",
+ "type": "Tracking method taken from the configuration at the start of the period.",
+ "startDate": "First date of the pay period (inclusive).",
+ "endDate": "Last date of the pay period (inclusive).",
+ "status": "Approval state of the timesheet: OPEN, PENDING_APPROVAL or APPROVED.",
+ "totalHours": "Sum of regular, overtime, holiday and approved time-off hours.",
+ "overtimeHours": "Part of totalHours that falls into the overtime rate.",
+ "approvedBy": "User who approved the timesheet. Null until approved.",
+ "approvedAt": "Time at which the timesheet was approved. Null until approved.",
+ "createdAt": "Time at which the timesheet was created.",
+ "updatedAt": "Time at which the timesheet was last changed.",
+ "hoursLastChangedAt": "Time at which the hours on the timesheet last changed.",
+ },
+ },
+ "hour_entries": {
+ "description": "A block of hours an employee entered against a date on a timesheet.",
+ "docs_url": "https://documentation.bamboohr.com/reference/list-hour-entries",
+ "columns": {
+ "id": "Unique identifier for the hour entry.",
+ "employeeId": "ID of the employee who worked the hours.",
+ "timesheetId": "ID of the timesheet the entry belongs to.",
+ "date": "The date the hours were worked.",
+ "hours": "Hours worked.",
+ "note": "Note attached to the entry.",
+ "projectId": "ID of the project the hours were booked to.",
+ "taskId": "ID of the task the hours were booked to.",
+ "createdAt": "Time at which the entry was created.",
+ "updatedAt": "Time at which the entry was last changed.",
+ },
+ },
+ "clock_entries": {
+ "description": "A clock-in and clock-out pair recorded by an employee on a timesheet.",
+ "docs_url": "https://documentation.bamboohr.com/reference/list-clock-entries",
+ "columns": {
+ "id": "Unique identifier for the clock entry.",
+ "employeeId": "ID of the employee the entry belongs to.",
+ "timesheetId": "ID of the timesheet (pay period) the entry belongs to.",
+ "date": "Calendar date the entry is attributed to, in the entry's timezone.",
+ "start": "Clock-in time, with the offset of the entry's timezone.",
+ "end": "Clock-out time. Null while the employee is clocked in.",
+ "timezone": "IANA timezone the start and end times were recorded in.",
+ "hours": "Hours between start and end. Zero while the entry is open.",
+ "note": "Note attached to the entry.",
+ "projectId": "ID of the project the time was booked to.",
+ "taskId": "ID of the task the time was booked to.",
+ "clockInLocation": "Location recorded at clock-in. Null when geolocation is off.",
+ "clockOutLocation": "Location recorded at clock-out. Null when geolocation is off or the entry is open.",
+ "schedulingShiftId": "ID of the scheduled shift the entry was worked against.",
+ "startSource": "Whether the start time was set by a user or by the system.",
+ "endSource": "Whether the end time was set by a user or by the system.",
+ "clockedInBy": "ID of the employee who recorded the clock-in.",
+ "clockedOutBy": "ID of the employee who recorded the clock-out.",
+ "createdAt": "Time at which the entry was created.",
+ "updatedAt": "Time at which the entry was last changed.",
+ },
+ },
+ "holidays": {
+ "description": "An active company holiday, with the employees it applies to and its pay treatment.",
+ "docs_url": "https://documentation.bamboohr.com/reference/list-company-holidays",
+ "columns": {
+ "id": "Unique identifier for the holiday.",
+ "name": "Name of the holiday.",
+ "startDate": "First date of the holiday.",
+ "endDate": "Last date of the holiday. Null for a single-day holiday.",
+ "isPublic": "Whether the holiday shows on every employee's calendar.",
+ "countryCodes": "ISO 3166-1 alpha-2 country codes the holiday is limited to. Empty means all countries.",
+ "audience": "The employees the holiday applies to.",
+ "holidayPay": "How the holiday is paid. Null means no special pay handling.",
+ "globalHolidayUuid": "ID of the catalog holiday this holiday was copied from. Null for a custom holiday.",
+ "createdAt": "Time at which the holiday was created.",
+ "updatedAt": "Time at which the holiday was last changed.",
+ },
+ },
+ "custom_fields": {
+ "description": "An active custom field or custom table defined for the company's employee records.",
+ "docs_url": "https://documentation.bamboohr.com/reference/list-custom-fields",
+ "columns": {
+ "id": "Unique identifier for the custom field or custom table.",
+ "legacyId": "Numeric ID of the custom field, as the older API endpoints use it.",
+ "name": "Name of the custom field or custom table.",
+ "type": "Type of the custom field or custom table.",
+ "isEncrypted": "Whether the custom field is encrypted.",
+ "isCalculated": "Whether the custom field is calculated.",
+ "isRequired": "Whether the custom field is required.",
+ "order": "Display order of the field.",
+ "pageId": "ID of the tab the field is on.",
+ "sectionId": "ID of the section the field is in.",
+ "customTableId": "ID of the custom table the field belongs to, for a custom table field.",
+ "values": "List values of a list or multi-list custom table field.",
+ "fields": "Fields of a custom table.",
+ },
+ },
+ "archived_custom_fields": {
+ "description": "An archived custom field or custom table that employee records can still refer to.",
+ "docs_url": "https://documentation.bamboohr.com/reference/list-archived-custom-fields",
+ "columns": {
+ "id": "Unique identifier for the custom field or custom table.",
+ "legacyId": "Numeric ID of the custom field, as the older API endpoints use it.",
+ "name": "Name of the custom field or custom table.",
+ "type": "Type of the custom field or custom table.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/settings.py
index a447d196f879..ed1027cdef66 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/settings.py
@@ -19,7 +19,9 @@ DataShape = Literal["list", "dict", "object"]
# "single" — the body is the whole response; never ask for a second page
# "page_number" — ``page``/``pageSize`` query params, walked until a page comes back empty
# "ats_applications" — the ATS applications envelope (``paginationComplete`` + ``nextPageUrl``)
-PaginationStyle = Literal["links", "single", "page_number", "ats_applications"]
+# "page_links" — ``page`` query param, taken from the ``_links.next.href`` object the
+# newer ``/api/v1`` collection endpoints return
+PaginationStyle = Literal["links", "single", "page_number", "ats_applications", "page_links"]
# The employee-table history endpoints group their rows under a map of employee id, and only that
# map carries the employee id and the timestamp of their last change — see ``bamboohr.py``.
@@ -31,6 +33,10 @@ GOAL_ID = "goalId"
# BambooHR's org locations endpoint is the only one that takes a page size.
LOCATIONS_PAGE_SIZE = 500
+# The documented maximum page size of each newer collection endpoint.
+TIME_TRACKING_PAGE_SIZE = 200
+HOLIDAYS_PAGE_SIZE = 100
+CUSTOM_FIELDS_PAGE_SIZE = 1000
@dataclass(frozen=True)
@@ -120,6 +126,19 @@ _APPLICATION_FANOUT = DependentEndpointConfig(
)
+def _time_tracking_endpoint(name: str, resource: str, sort: str) -> BambooHREndpointConfig:
+ return BambooHREndpointConfig(
+ name=name,
+ path=f"v1/time-tracking/{resource}",
+ data_key="data",
+ primary_keys=["id"],
+ pagination="page_links",
+ # The default sort is newest first, so a row added during the walk would shift every
+ # later page by one and skip a row at each page boundary.
+ params={"sort": sort, "pageSize": TIME_TRACKING_PAGE_SIZE},
+ )
+
+
def _employee_table_endpoint(name: str, table: str) -> BambooHREndpointConfig:
return BambooHREndpointConfig(
name=name,
@@ -263,6 +282,35 @@ BAMBOOHR_ENDPOINTS: dict[str, BambooHREndpointConfig] = {
primary_keys=[EMPLOYEE_TABLE_EMPLOYEE_ID, GOAL_ID, "id"],
custom_iterator="goal_comments",
),
+ # The time-tracking, holiday and custom-field collections have no "changed since" filter
+ # (only work-date filters), so an edit to an older entry is only picked up by a full refresh.
+ "timesheets": _time_tracking_endpoint("timesheets", "timesheets", "startDate asc"),
+ "hour_entries": _time_tracking_endpoint("hour_entries", "hour-entries", "date asc"),
+ "clock_entries": _time_tracking_endpoint("clock_entries", "clock-entries", "start asc"),
+ "holidays": BambooHREndpointConfig(
+ name="holidays",
+ path="v1/holidays",
+ data_key="data",
+ primary_keys=["id"],
+ pagination="page_links",
+ params={"orderBy": "startDate asc", "pageSize": HOLIDAYS_PAGE_SIZE},
+ ),
+ "custom_fields": BambooHREndpointConfig(
+ name="custom_fields",
+ path="v1/hris/custom-fields",
+ data_key="data",
+ primary_keys=["id"],
+ pagination="page_links",
+ params={"pageSize": CUSTOM_FIELDS_PAGE_SIZE},
+ ),
+ "archived_custom_fields": BambooHREndpointConfig(
+ name="archived_custom_fields",
+ path="v1/hris/custom-fields/archived",
+ data_key="data",
+ primary_keys=["id"],
+ pagination="page_links",
+ params={"pageSize": CUSTOM_FIELDS_PAGE_SIZE},
+ ),
}
ENDPOINTS = tuple(BAMBOOHR_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/tests/test_bamboohr.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/tests/test_bamboohr.py
index d09ac0f7f6a8..fa82e0aabaf9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/tests/test_bamboohr.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bamboohr/tests/test_bamboohr.py
@@ -645,6 +645,42 @@ class TestApplicationsPagination:
assert _page_from_url(url) == expected
+class TestPageLinksPagination:
+ @parameterized.expand(
+ [
+ ("timesheets", "v1/time-tracking/timesheets", {"sort": "startDate asc", "pageSize": 200}, {}),
+ ("hour_entries", "v1/time-tracking/hour-entries", {"sort": "date asc", "pageSize": 200}, {}),
+ ("clock_entries", "v1/time-tracking/clock-entries", {"sort": "start asc", "pageSize": 200}, {}),
+ ("holidays", "v1/holidays", {"orderBy": "startDate asc", "pageSize": 100}, {"next": None}),
+ ("custom_fields", "v1/hris/custom-fields", {"pageSize": 1000}, {"next": None}),
+ ("archived_custom_fields", "v1/hris/custom-fields/archived", {"pageSize": 1000}, {}),
+ ]
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_walks_pages_by_the_next_link(
+ self, endpoint: str, path: str, params: dict[str, Any], last_links: dict[str, Any], MockSession
+ ) -> None:
+ page1 = {
+ "data": [{"id": 1}],
+ "meta": {"page": 1, "pageSize": 1, "totalPages": 2, "totalItems": 2},
+ "_links": {"next": {"href": f"https://acme.bamboohr.com/api/{path}?page=2&pageSize=1"}},
+ }
+ page2 = {
+ "data": [{"id": 2}],
+ "meta": {"page": 2, "pageSize": 1, "totalPages": 2, "totalItems": 2},
+ "_links": last_links,
+ }
+
+ rows, requests_made, _manager = _run(endpoint, [_response(page1), _response(page2)], MockSession)
+
+ assert [r["id"] for r in rows] == [1, 2]
+ # The next link points at the company domain, so the walk stays on the gateway and only
+ # reuses the link's page number.
+ assert [r["url"] for r in requests_made] == [f"https://api.bamboohr.com/api/gateway.php/acme/{path}"] * 2
+ assert requests_made[0]["params"] == params
+ assert requests_made[1]["params"] == {**params, "page": 2}
+
+
class TestLocationsPagination:
@mock.patch(CLIENT_SESSION_PATCH)
def test_walks_every_page_of_active_and_archived_locations(self, MockSession) -> None: