: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): add 4 missing tables to the Slash source (#121350)
Tom Owers5a819a4bda4e
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.mdindex 055690cfb37f..c9c97a27ef73 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@@ -11200,10 +11200,10 @@ Today (7): `accounts`, `cards`, `contacts`, `expense_reports`, `invoice_series`,Diffed against: <https://docs.slash.com/llms-full.txt>-- [ ] `List account balances (GET /account/{accountId}/balance)` — measure available and posted cash or credit; account rows list balance types without amounts (high)-- [ ] `List virtual accounts (GET /virtual-account)` — resolve virtualAccountId on cards and transactions for spending and allocation analysis (high)-- [ ] `List card groups (GET /card-group)` — resolve cardGroupId and compare spending across groups of cards (high)-- [ ] `List customers (GET /customer)` — resolve legalEntityCustomerId on invoices and analyze billing recipients separately from contacts (high)+- [x] `List account balances (GET /account/{accountId}/balance)` — measure available and posted cash or credit; account rows list balance types without amounts (high)+- [x] `List virtual accounts (GET /virtual-account)` — resolve virtualAccountId on cards and transactions for spending and allocation analysis (high)+- [x] `List card groups (GET /card-group)` — resolve cardGroupId and compare spending across groups of cards (high)+- [x] `List customers (GET /customer)` — resolve legalEntityCustomerId on invoices and analyze billing recipients separately from contacts (high)- [ ] `List cardholders (GET /cardholder)` — analyze the people assigned to corporate cards (medium)- [ ] `List legal entities (GET /legal-entity)` — compare business entities available to a user and organize financial reporting across them (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/canonical_descriptions.pyindex ac5d52e922fd..fb71f8c1ca6d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/canonical_descriptions.py@@ -77,4 +77,49 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"archivedAt": "Time when the contact was archived. Empty for active contacts.",},},+ "virtual_accounts": {+ "description": "Virtual accounts under each Slash account, including the primary account and closed accounts.",+ "docs_url": "https://docs.slash.com/api-reference/virtual-account-get",+ "columns": {+ "id": "Unique virtual account identifier, copied from the nested virtual account object.",+ "virtualAccount": "The virtual account, with its name, account ID, account type, and close time.",+ "balance": "Total balance of the virtual account, in cents.",+ "spend": "Total spend of the virtual account, in cents.",+ "commissionRule": "Commission rule applied to the virtual account, if any.",+ },+ },+ "card_groups": {+ "description": "Active card groups that share a spending constraint.",+ "docs_url": "https://docs.slash.com/api-reference/card-group-get",+ "columns": {+ "id": "Unique card group identifier.",+ "name": "Name of the card group.",+ "virtualAccountId": "Deprecated legacy virtual account association. Empty when none exists.",+ "spendingConstraint": "Spending rules that apply to the cards in the group.",+ },+ },+ "customers": {+ "description": "Billing recipients for invoices of the legal entity.",+ "docs_url": "https://docs.slash.com/api-reference/customer-get",+ "columns": {+ "id": "Unique customer identifier.",+ "name": "Display name of the customer.",+ "email": "Email address of the customer.",+ "phone": "Phone number of the customer.",+ "address": "Address of the customer.",+ "customMetadata": "Custom metadata associated with the customer.",+ "status": "Whether the customer is active or archived.",+ },+ },+ "account_balances": {+ "description": "Current balances of each Slash account. Charge card accounts have cash and credit balances.",+ "docs_url": "https://docs.slash.com/api-reference/account-balance-get",+ "columns": {+ "accountId": "Identifier of the account associated with the balance.",+ "type": "Balance type: cash, credit, or debit.",+ "available": "Amount in cents that is available to use immediately.",+ "posted": "Amount in cents posted to the balance. Pending transactions are not included.",+ "timestamp": "UTC time when Slash computed the balance.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/settings.pyindex a0a54c60a014..4f4fd340b81a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/settings.py@@ -10,8 +10,14 @@ ENDPOINTS = {"invoice_series": "invoice-series","expense_reports": "expense-report","contacts": "contact",+ "virtual_accounts": "virtual-account",+ "card_groups": "card-group",+ "customers": "customer",+ "account_balances": "account/{accountId}/balance",}+PRIMARY_KEYS = {"account_balances": ["accountId", "type"]}+INCREMENTAL_FIELDS = {"transactions": [incremental_field("date")]}AUTH_ERROR = "Slash rejected the API key. Check the key in your Slash dashboard."diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/slash.py b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/slash.pyindex a7b0b2a663d0..30fe9e1721de 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/slash.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/slash.py@@ -8,6 +8,7 @@ from posthog.dataclasses import frozenfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (RESTAPIConfig,rest_api_resource,+ rest_api_resources,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.auth import APIKeyAuthfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (@@ -15,8 +16,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client import RESTClientfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (+ ClientConfig,Endpoint,EndpointResource,+ JSONResponseCursorPaginatorConfig,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import schema_for_resource@@ -27,9 +30,17 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.slash.settBASE_URL,ENDPOINTS,PERMISSION_ERROR,+ PRIMARY_KEYS,REQUEST_ERROR,)+CURSOR_PAGINATOR: JSONResponseCursorPaginatorConfig = {+ "type": "cursor",+ "cursor_path": "metadata.nextCursor",+ "cursor_param": "cursor",+ "raise_on_repeated_cursor": True,+}+@frozenclass SlashResumeConfig:@@ -40,8 +51,24 @@ def invoice_with_id(row: dict[str, Any]) -> dict[str, Any]:return {**row, "id": row["invoice"]["id"]}+def virtual_account_with_id(row: dict[str, Any]) -> dict[str, Any]:+ return {**row, "id": row["virtualAccount"]["id"]}+++def client_config(config: SlashSourceConfig) -> ClientConfig:+ return {+ "base_url": BASE_URL,+ "auth": {"type": "api_key", "api_key": config.api_key, "name": "X-API-Key", "location": "header"},+ "headers": {"x-legal-entity": config.legal_entity_id} if config.legal_entity_id else {},+ "allow_redirects": False,+ "request_timeout": (10, 60),+ }++def validate_credentials(config: SlashSourceConfig, schema_name: str | None) -> tuple[bool, str | None]:- path = schema_for_resource(ENDPOINTS, schema_name or "accounts")+ # Balances need an account ID in the path, so probe the account listing they fan out from.+ probe = "accounts" if schema_name is None or schema_name == "account_balances" else schema_name+ path = schema_for_resource(ENDPOINTS, probe)client = RESTClient(base_url=BASE_URL,auth=APIKeyAuth(api_key=config.api_key, name="X-API-Key"),@@ -74,6 +101,9 @@ def slash_source(db_incremental_field_last_value: datetime | str | None,) -> SourceResponse:path = schema_for_resource(ENDPOINTS, endpoint)+ if endpoint == "account_balances":+ return account_balances_source(config, team_id, job_id)+params: dict[str, Any] = {}if endpoint == "transactions" and should_use_incremental_field and db_incremental_field_last_value is not None:watermark = db_incremental_field_last_value@@ -82,35 +112,23 @@ def slash_source(if watermark.tzinfo is None:watermark = watermark.replace(tzinfo=UTC)params["filter:from_date"] = int(watermark.timestamp() * 1000)+ if endpoint == "virtual_accounts":+ params["filter:includeClosedAccounts"] = "true"endpoint_config: Endpoint = {"path": path,"params": params,"data_selector": "items","data_selector_required": True,- "paginator": "single_page"- if endpoint == "accounts"- else {- "type": "cursor",- "cursor_path": "metadata.nextCursor",- "cursor_param": "cursor",- "raise_on_repeated_cursor": True,- },+ "paginator": "single_page" if endpoint == "accounts" else CURSOR_PAGINATOR,}resource_config: EndpointResource = {"name": endpoint, "endpoint": endpoint_config}if endpoint == "invoices":resource_config["data_map"] = invoice_with_id+ elif endpoint == "virtual_accounts":+ resource_config["data_map"] = virtual_account_with_id- rest_config: RESTAPIConfig = {- "client": {- "base_url": BASE_URL,- "auth": {"type": "api_key", "api_key": config.api_key, "name": "X-API-Key", "location": "header"},- "headers": {"x-legal-entity": config.legal_entity_id} if config.legal_entity_id else {},- "allow_redirects": False,- "request_timeout": (10, 60),- },- "resources": [resource_config],- }+ rest_config: RESTAPIConfig = {"client": client_config(config), "resources": [resource_config]}resume = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else Nonedef save_checkpoint(state: dict[str, Any] | None) -> None:@@ -133,3 +151,37 @@ def slash_source(sort_mode="desc",supports_resume=endpoint != "accounts",)+++def account_balances_source(config: SlashSourceConfig, team_id: int, job_id: str) -> SourceResponse:+ rest_config: RESTAPIConfig = {+ "client": client_config(config),+ "resources": [+ {+ "name": "accounts",+ "endpoint": {+ "path": ENDPOINTS["accounts"],+ "data_selector": "items",+ "data_selector_required": True,+ "paginator": "single_page",+ },+ },+ {+ "name": "account_balances",+ "endpoint": {+ "path": ENDPOINTS["account_balances"],+ "params": {"accountId": {"type": "resolve", "resource": "accounts", "field": "id"}},+ "data_selector": "balances",+ "data_selector_required": True,+ "paginator": "single_page",+ },+ },+ ],+ }+ resources = {resource.name: resource for resource in rest_api_resources(rest_config, team_id, job_id, None)}+ resource = resources["account_balances"]+ return SourceResponse(+ name="account_balances",+ items=lambda: resource,+ primary_keys=PRIMARY_KEYS["account_balances"],+ )diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/tests/test_slash.py b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/tests/test_slash.pyindex 5d0ed9685fdb..ac4703d81aca 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/slash/tests/test_slash.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/slash/tests/test_slash.py@@ -27,32 +27,105 @@ def _run(endpoint: str, script: Script, legal_entity_id: str | None = None, **in@pytest.mark.parametrize(- ("endpoint", "path", "row"),+ ("endpoint", "path", "row", "id_path", "query"),[- ("accounts", "account", {"id": "account-example"}),- ("transactions", "transaction", {"id": "transaction-example", "date": "2026-01-02T00:00:00Z"}),- ("cards", "card", {"id": "card-example"}),- ("invoices", "invoice", {"invoice": {"id": "invoice-example"}, "invoiceDetails": {"memo": "Example"}}),- ("invoice_series", "invoice-series", {"id": "series-example"}),- ("expense_reports", "expense-report", {"id": "expense-example"}),- ("contacts", "contact", {"id": "contact-example"}),+ ("accounts", "account", {"id": "account-example"}, None, {}),+ (+ "transactions",+ "transaction",+ {"id": "transaction-example", "date": "2026-01-02T00:00:00Z"},+ None,+ {},+ ),+ ("cards", "card", {"id": "card-example"}, None, {}),+ (+ "invoices",+ "invoice",+ {"invoice": {"id": "invoice-example"}, "invoiceDetails": {"memo": "Example"}},+ "invoice",+ {},+ ),+ ("invoice_series", "invoice-series", {"id": "series-example"}, None, {}),+ ("expense_reports", "expense-report", {"id": "expense-example"}, None, {}),+ ("contacts", "contact", {"id": "contact-example"}, None, {}),+ (+ "virtual_accounts",+ "virtual-account",+ {+ "virtualAccount": {"id": "virtual-example", "accountType": "primary", "closedAt": None},+ "balance": {"amountCents": 1200},+ "spend": {"amountCents": 300},+ },+ "virtualAccount",+ {"filter:includeClosedAccounts": ("true",)},+ ),+ ("card_groups", "card-group", {"id": "group-example", "name": "Example group"}, None, {}),+ ("customers", "customer", {"id": "customer-example", "status": "archived"}, None, {}),],)@pytest.mark.parametrize("legal_entity_id", [None, "entity-example"])-def test_requests_and_row_identity(endpoint: str, path: str, row: dict[str, Any], legal_entity_id: str | None) -> None:+def test_requests_and_row_identity(+ endpoint: str,+ path: str,+ row: dict[str, Any],+ id_path: str | None,+ query: dict[str, tuple[str, ...]],+ legal_entity_id: str | None,+) -> None:result = _run(endpoint,[ScriptedResponse(json={"items": [row], "metadata": {"count": 1}})],legal_entity_id,db_incremental_field_last_value="2026-01-01T00:00:00Z",)- expected = {**row, "id": row["invoice"]["id"]} if endpoint == "invoices" else row+ expected = {**row, "id": row[id_path]["id"]} if id_path else rowassert result.rows == [expected]assert result.paths == [f"/{path}"]request = result.requests[0]assert request.headers["x-api-key"] == "fake-key"assert request.headers.get("x-legal-entity") == legal_entity_id- assert request.query == {}+ assert request.query == query+ assert result.saved_states == []+++def test_account_balances_fan_out_over_accounts() -> None:+ balance = {+ "accountId": "account-one",+ "type": "debit",+ "available": {"amountCents": 500},+ "posted": {"amountCents": 700},+ "timestamp": "2026-01-02T00:00:00Z",+ }+ result = _run(+ "account_balances",+ [+ ScriptedResponse(json={"items": [{"id": "account-one"}, {"id": "account-two"}, {"id": "account-three"}]}),+ ScriptedResponse(json={"balances": [balance]}),+ ScriptedResponse(json={"balances": []}),+ ScriptedResponse(+ json={+ "balances": [+ {**balance, "accountId": "account-three", "type": "cash"},+ {**balance, "accountId": "account-three", "type": "credit"},+ ]+ }+ ),+ ],+ "entity-example",+ )+ assert result.raised is None+ assert result.paths == [+ "/account",+ "/account/account-one/balance",+ "/account/account-two/balance",+ "/account/account-three/balance",+ ]+ assert all(request.headers["x-legal-entity"] == "entity-example" for request in result.requests)+ assert [(row["accountId"], row["type"]) for row in result.rows] == [+ ("account-one", "debit"),+ ("account-three", "cash"),+ ("account-three", "credit"),+ ]assert result.saved_states == []@@ -115,20 +188,27 @@ def test_repeated_cursor_fails() -> None:@pytest.mark.parametrize(- ("status", "schema", "expected", "message"),+ ("status", "schema", "path", "expected", "message"),[- (403, None, True, None),+ (403, None, "/account", True, None),(403,"cards",+ "/card",+ False,+ "Your Slash key cannot access this resource. Check its permissions and the legal entity ID.",+ ),+ (400, None, "/account", False, "Slash rejected the request. User-scoped keys require a valid legal entity ID."),+ (+ 403,+ "account_balances",+ "/account",False,"Your Slash key cannot access this resource. Check its permissions and the legal entity ID.",),- (400, None, False, "Slash rejected the request. User-scoped keys require a valid legal entity ID."),],)-def test_credential_probe(status: int, schema: str | None, expected: bool, message: str | None) -> None:- path = "/card" if schema else "/account"+def test_credential_probe(status: int, schema: str | None, path: str, expected: bool, message: str | None) -> None:script = [ScriptedResponse(status=status, json={"items": [], "metadata": {"nextCursor": "unused"}})]with scripted_network(script) as network:outcome = validate_credentials(SlashSourceConfig(api_key="fake-key", legal_entity_id="entity-example"), schema)