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(data-warehouse): add 7shifts pos lookup tables (#126945)

Tom Owersd3287507742f
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 8ad54f6d461b..3ad2d6c2816f 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
@@ -35,7 +35,7 @@ Note: Compared the official Rooms reference, SDK resource modules, and external
## 7shifts — **thin**
-Today (6): `departments`, `locations`, `roles`, `shifts`, `time_punches`, `users`
+Today (9): `departments`, `dining_options`, `locations`, `revenue_centers`, `roles`, `sales_categories`, `shifts`, `time_punches`, `users`
Diffed against: <https://developers.7shifts.com/llms.txt>
@@ -49,6 +49,9 @@ Diffed against: <https://developers.7shifts.com/llms.txt>
- [ ] `Tip pool detailed report (GET /v2/company/{company_id}/locations/{location_id}/tip_pool_detailed_report)` — compare tip allocations by employee and location with hours and wages (medium)
- [ ] `Orders (GET /v2/company/{company_id}/location/{location_id}/orders)` — analyze sales, payments, and purchased items at each location alongside staffing (medium)
- [ ] `Shift feedback (GET /v2/company/{company_id}/shift_feedback)` — compare employee shift feedback with workload, attendance, and staffing levels (medium)
+- [x] `POS revenue centers (GET /v2/company/{company_id}/location/{location_id}/revenue_centers)` — resolve the revenue center on POS orders to a name per location (low) → `revenue_centers` (full refresh, fan-out over `locations`)
+- [x] `POS sales categories (GET /v2/company/{company_id}/location/{location_id}/sales_categories)` — resolve the sales category on POS order items to a name per location (low) → `sales_categories` (full refresh, fan-out over `locations`)
+- [x] `POS dining options (GET /v2/company/{company_id}/location/{location_id}/dining_options)` — resolve the dining option on POS orders to a name and service mode per location (low) → `dining_options` (full refresh, fan-out over `locations`)
Note: Parsed the official documentation index and OpenAPI blocks on individual operation pages. Wage and assignment collections require requests for each user; reports require company and date filters. The source pins 2026-01-01; orders appear in the latest reference and have a 90-day limit. Version and plan requirements need checks; excluded writes, OAuth, webhooks, and task configuration.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/canonical_descriptions.py
index 746c49be66fe..61d78c47a9d2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/canonical_descriptions.py
@@ -71,4 +71,32 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"modified": "The time when the time punch was last modified, in UTC.",
},
},
+ "revenue_centers": {
+ "description": "POS revenue centers for each location, such as a bar or patio, from any integration.",
+ "docs_url": "https://developers.7shifts.com/reference/listposrevenuecenters",
+ "columns": {
+ "external_id": "The POS system's unique identifier for the revenue center.",
+ "name": "Display name of the revenue center.",
+ "location_id": "The 7shifts location this revenue center belongs to.",
+ },
+ },
+ "sales_categories": {
+ "description": "POS sales categories for each location, from any integration.",
+ "docs_url": "https://developers.7shifts.com/reference/listpossalescategories",
+ "columns": {
+ "external_id": "The POS system's unique identifier for the sales category.",
+ "name": "Display name of the sales category.",
+ "location_id": "The 7shifts location this sales category belongs to.",
+ },
+ },
+ "dining_options": {
+ "description": "POS dining options for each location, such as dine-in, takeout, or delivery, from any integration.",
+ "docs_url": "https://developers.7shifts.com/reference/listposdiningoptions",
+ "columns": {
+ "external_id": "The POS system's unique identifier for the dining option.",
+ "name": "Display name of the dining option.",
+ "location_id": "The 7shifts location this dining option belongs to.",
+ "type": "The POS system's service-mode classification of the dining option, such as dine_in, takeout, or delivery.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/settings.py
index 9995f03cfef7..672a587e1950 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/settings.py
@@ -1,9 +1,46 @@
+from dataclasses import field
+from typing import Any
+
+from posthog.dataclasses import frozen
+
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import incremental_field
BASE_URL = "https://api.7shifts.com/v2/"
-ENDPOINTS = ("locations", "departments", "roles", "users", "shifts", "time_punches")
+INCREMENTAL_ENDPOINTS = ("locations", "departments", "roles", "users", "shifts", "time_punches")
DATE_ONLY_ENDPOINTS = frozenset({"locations", "departments", "roles", "users"})
-INCREMENTAL_FIELDS = {name: [incremental_field("modified")] for name in ENDPOINTS}
+INCREMENTAL_FIELDS = {name: [incremental_field("modified")] for name in INCREMENTAL_ENDPOINTS}
+
+
+@frozen
+class SevenShiftsEndpointConfig:
+ name: str
+ path: str
+ page_size: int = 100
+ incremental_fields: list[Any] = field(default_factory=list)
+ default_incremental_field: str | None = None
+
+
+# POS lookups are listed per location and carry no modified timestamp, so they sync as full refresh.
+LOCATION_ENDPOINT_CONFIGS = {
+ config.name: config
+ for config in (
+ SevenShiftsEndpointConfig(name="locations", path="{company}/locations"),
+ SevenShiftsEndpointConfig(name="revenue_centers", path="{company}/location/{location_id}/revenue_centers"),
+ SevenShiftsEndpointConfig(name="sales_categories", path="{company}/location/{location_id}/sales_categories"),
+ SevenShiftsEndpointConfig(name="dining_options", path="{company}/location/{location_id}/dining_options"),
+ )
+}
+LOCATION_ENDPOINTS = ("revenue_centers", "sales_categories", "dining_options")
+LOCATION_FANOUT = DependentEndpointConfig(
+ parent_name="locations", resolve_param="location_id", resolve_field="id", include_from_parent=[]
+)
+# external_id comes from the POS system, so it is only unique within a location.
+LOCATION_PRIMARY_KEYS = ["location_id", "external_id"]
+
+ENDPOINTS = (*INCREMENTAL_ENDPOINTS, *LOCATION_ENDPOINTS)
AUTH_ERROR = "7shifts rejected the access token. Create a token in Settings > Developer Tools, then reconnect."
ACCESS_ERROR = "7shifts denied access. Check the company ID, token administrator, and your plan's API access."
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/sevenshifts.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/sevenshifts.py
index 78d20f605027..d84db0277e5e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/sevenshifts.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/sevenshifts.py
@@ -1,17 +1,23 @@
+from collections.abc import Mapping
from datetime import UTC, datetime, timedelta
-from typing import Any
+from typing import Any, cast
from requests import HTTPError
from posthog.dataclasses import frozen
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (
+ ClientConfig,
Endpoint,
EndpointResource,
RESTAPIConfig,
rest_api_resource,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.auth import BearerTokenAuth
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ FanoutEndpointLike,
+ build_dependent_resource,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
SinglePagePaginator,
)
@@ -29,12 +35,17 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.sevenshift
COMPANY_ERROR,
DATE_ONLY_ENDPOINTS,
ENDPOINTS,
+ LOCATION_ENDPOINT_CONFIGS,
+ LOCATION_ENDPOINTS,
+ LOCATION_FANOUT,
+ LOCATION_PRIMARY_KEYS,
)
@frozen
class SevenShiftsResumeConfig:
- cursor: str
+ cursor: str | None = None
+ fanout_state: dict[str, Any] | None = None
def company_path(company_id: str) -> str:
@@ -72,6 +83,60 @@ def validate_credentials(config: SevenShiftsSourceConfig, api_version: str) -> t
return True, None
+def _client_config(config: SevenShiftsSourceConfig, api_version: str) -> ClientConfig:
+ return {
+ "base_url": BASE_URL,
+ "auth": {"type": "bearer", "token": config.access_token},
+ "headers": {"x-api-version": api_version},
+ "paginator": {
+ "type": "cursor",
+ "cursor_path": "meta.cursor.next",
+ "cursor_param": "cursor",
+ "raise_on_repeated_cursor": True,
+ },
+ "allowed_hosts": [],
+ "allow_redirects": False,
+ "request_timeout": 30,
+ }
+
+
+def _location_source(
+ config: SevenShiftsSourceConfig,
+ endpoint: str,
+ api_version: str,
+ team_id: int,
+ job_id: str,
+ manager: ResumableSourceManager[SevenShiftsResumeConfig],
+) -> SourceResponse:
+ resume = manager.load_state() if manager.can_resume() else None
+
+ def save_checkpoint(state: dict[str, Any] | None) -> None:
+ if state:
+ manager.save_state(SevenShiftsResumeConfig(fanout_state=state))
+
+ data_selector: Endpoint = {"data_selector": "data", "data_selector_required": True}
+ resource = build_dependent_resource(
+ endpoint_configs=cast(Mapping[str, FanoutEndpointLike], LOCATION_ENDPOINT_CONFIGS),
+ child_endpoint=endpoint,
+ fanout=LOCATION_FANOUT,
+ client_config=_client_config(config, api_version),
+ path_format_values={"company": company_path(config.company_id)},
+ team_id=team_id,
+ job_id=job_id,
+ db_incremental_field_last_value=None,
+ parent_endpoint_extra=data_selector,
+ child_endpoint_extra=data_selector,
+ resume_hook=save_checkpoint,
+ initial_paginator_state=resume.fanout_state if resume else None,
+ )
+ return SourceResponse(
+ name=endpoint,
+ items=lambda: resource,
+ primary_keys=LOCATION_PRIMARY_KEYS,
+ on_complete=manager.clear_state,
+ )
+
+
def sevenshifts_source(
config: SevenShiftsSourceConfig,
endpoint: str,
@@ -83,6 +148,9 @@ def sevenshifts_source(
last_value: datetime | str | None,
) -> SourceResponse:
schema_for_resource(dict.fromkeys(ENDPOINTS), endpoint)
+ if endpoint in LOCATION_ENDPOINTS:
+ return _location_source(config, endpoint, api_version, team_id, job_id, manager)
+
params: dict[str, Any] = {"limit": 100}
if endpoint == "shifts":
params["include_deleted"] = "true"
@@ -104,20 +172,7 @@ def sevenshifts_source(
}
resource_config: EndpointResource = {"name": endpoint, "endpoint": endpoint_config}
rest_config: RESTAPIConfig = {
- "client": {
- "base_url": BASE_URL,
- "auth": {"type": "bearer", "token": config.access_token},
- "headers": {"x-api-version": api_version},
- "paginator": {
- "type": "cursor",
- "cursor_path": "meta.cursor.next",
- "cursor_param": "cursor",
- "raise_on_repeated_cursor": True,
- },
- "allowed_hosts": [],
- "allow_redirects": False,
- "request_timeout": 30,
- },
+ "client": _client_config(config, api_version),
"resources": [resource_config],
}
resume = manager.load_state() if manager.can_resume() else None
@@ -132,7 +187,7 @@ def sevenshifts_source(
job_id,
None,
resume_hook=save_checkpoint,
- initial_paginator_state={"cursor": resume.cursor} if resume else None,
+ initial_paginator_state={"cursor": resume.cursor} if resume and resume.cursor else None,
)
return SourceResponse(
name=endpoint,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/tests/test_sevenshifts.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/tests/test_sevenshifts.py
index dbf6073e8d0d..05257bc30e75 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/tests/test_sevenshifts.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sevenshifts/tests/test_sevenshifts.py
@@ -68,6 +68,34 @@ def test_incremental_filter_and_full_refresh(
assert result.params("modified_since") == ([expected] * 2 if incremental else [None] * 2)
[email protected]("endpoint", ["revenue_centers", "sales_categories", "dining_options"])
+def test_location_lookup_walks_every_location(driver: SourceDriver, endpoint: str) -> None:
+ result = driver.run(
+ endpoint,
+ [
+ response([{"id": 11}], "locations-two"),
+ response([{"external_id": "a", "name": "A", "location_id": 11}], "child-two"),
+ response([{"external_id": "b", "name": "B", "location_id": 11}]),
+ response([{"id": 22}]),
+ response([{"external_id": "a", "name": "A", "location_id": 22}]),
+ ],
+ should_use_incremental_field=True,
+ db_incremental_field_last_value="2026-03-05T12:30:00Z",
+ )
+
+ assert result.raised is None
+ assert result.paths == [
+ "/v2/company/123/locations",
+ f"/v2/company/123/location/11/{endpoint}",
+ f"/v2/company/123/location/11/{endpoint}",
+ "/v2/company/123/locations",
+ f"/v2/company/123/location/22/{endpoint}",
+ ]
+ assert result.params("cursor") == [None, None, "child-two", "locations-two", None]
+ assert result.params("modified_since") == [None] * 5
+ assert [(row["location_id"], row["external_id"]) for row in result.rows] == [(11, "a"), (11, "b"), (22, "a")]
+
+
def test_repeated_cursor_fails(driver: SourceDriver) -> None:
result = driver.run("users", [response([{"id": 1}], "same-cursor"), response([{"id": 1}], "same-cursor")])