: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 insightly lead status, ticket, quote, and product tables (#111881)
Tom Owers6126c5bdae54
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 dda9368b090d..c9d71be8a525 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@@ -4318,10 +4318,10 @@ Diffed against: <https://api.insightly.com/v3.1/swagger/docs/v3.1>- [x] `/OpportunityLineItem` — line-item revenue detail behind each opportunity; the deal header alone cannot break revenue down by product (high)- [x] `/Opportunities/{id}/StateHistory` — won/lost/abandoned state transition history - the only source for sales-cycle and stage-velocity analysis (pair with /OpportunityStateReasons) (high)- [x] `/LeadSources` — lookup resolving LEAD_SOURCE_ID on Leads - the core attribution dimension (high)-- [ ] `/LeadStatuses` — lookup resolving LEAD_STATUS_ID on Leads, needed for any lead funnel (high)-- [ ] `/Ticket` — Insightly Service tickets, an entire product area with no table today (high)-- [ ] `/Quotation and /QuotationLineItem` — quotes and their line items, the pre-close revenue pipeline (medium)-- [ ] `/Product, /Pricebook, /PricebookEntry` — lookups resolving PRODUCT_ID and PRICEBOOK_ENTRY_ID on opportunity and quotation line items (medium)+- [x] `/LeadStatuses` — lookup resolving LEAD_STATUS_ID on Leads, needed for any lead funnel (high). Added as `LeadStatuses`, including the converted status.+- [x] `/Ticket` — Insightly Service tickets, an entire product area with no table today (high). Added as `Ticket`.+- [x] `/Quotation and /QuotationLineItem` — quotes and their line items, the pre-close revenue pipeline (medium). Added as `Quotation` and `QuotationLineItem`.+- [x] `/Product, /Pricebook, /PricebookEntry` — lookups resolving PRODUCT_ID and PRICEBOOK_ENTRY_ID on opportunity and quotation line items (medium). Added as `Product`, `Pricebook`, and `PricebookEntry`.- [ ] `/Milestones` — project milestones and their completion dates, the delivery-tracking grain under Projects (medium)- [ ] `/OpportunityCategories, /ProjectCategories, /TaskCategories` — lookups resolving the CATEGORY_ID already present on the synced opportunities, projects and tasks (medium)- [ ] `/Teams and /TeamMembers` — team membership for rolling per-rep opportunity and task metrics up to teams (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/canonical_descriptions.pyindex 5c2799d27e53..d3eeb584bb7c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/canonical_descriptions.py@@ -199,6 +199,121 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"CUSTOMFIELDS": "List of custom field values defined for your Insightly account.",},},+ "LeadStatuses": {+ "description": "Lead status values defined for your Insightly account, referenced by LEAD_STATUS_ID on leads.",+ "docs_url": _DOCS_URL,+ "columns": {+ "LEAD_STATUS_ID": "Unique identifier for the lead status.",+ "LEAD_STATUS": "Name of the lead status.",+ "DEFAULT_STATUS": "Whether this is the default status for new leads.",+ "FIELD_ORDER": "Display order of the lead status in pick lists.",+ },+ },+ "Ticket": {+ "description": "Insightly Service support tickets raised by contacts.",+ "docs_url": _DOCS_URL,+ "columns": _columns(+ TICKET_ID="Unique identifier for the ticket.",+ TICKET_NUMBER="Human-readable ticket number.",+ SUBJECT="Ticket subject line.",+ TICKET_STATUS="Current status of the ticket.",+ TICKET_TYPE="Type of the ticket.",+ PRIORITY="Priority of the ticket.",+ SOURCE="Channel the ticket came in through.",+ CONTACT_ID="ID of the contact who raised the ticket.",+ ORGANISATION_ID="ID of the organisation linked to the ticket, if any.",+ TO_EMAIL_ADDRESS="Email address the ticket was sent to.",+ BRAND_ID="ID of the brand the ticket belongs to.",+ DATE_SOLVED_UTC="UTC timestamp when the ticket was solved, if it has been.",+ DATE_CLOSED_UTC="UTC timestamp when the ticket was closed, if it has been.",+ ),+ },+ "Quotation": {+ "description": "Quotes sent for opportunities, with their totals, status, and addresses.",+ "docs_url": _DOCS_URL,+ "columns": _columns(+ QUOTE_ID="Unique identifier for the quote.",+ QUOTATION_NAME="Name of the quote.",+ QUOTATION_NUMBER="Quote number.",+ QUOTE_STATUS="Current status of the quote.",+ OPPORTUNITY_ID="ID of the opportunity the quote belongs to.",+ CONTACT_ID="ID of the contact the quote is addressed to, if any.",+ ORGANISATION_ID="ID of the organisation the quote is addressed to, if any.",+ PRICEBOOK_ID="ID of the price book the quote uses.",+ QUOTATION_EXPIRATION_DATE="Date the quote expires.",+ QUOTATION_CURRENCY_CODE="Currency of the quote prices.",+ LINE_ITEM_COUNT="Number of line items on the quote.",+ IS_SYNCING="Whether the quote syncs its line items with the opportunity.",+ SUBTOTAL="Total of the line items before discount.",+ DISCOUNT="Discount applied to the quote.",+ TOTAL_PRICE="Total of the line items after discount.",+ SHIPPING_HANDLING="Shipping and handling charge.",+ TAX="Tax charged on the quote.",+ GRAND_TOTAL="Final quote amount, including shipping and tax.",+ ),+ },+ "QuotationLineItem": {+ "description": "Products on a quote, with quantity, pricing, and discount.",+ "docs_url": _DOCS_URL,+ "columns": {+ "QUOTATION_ITEM_ID": "Unique identifier for the quote line item.",+ "QUOTE_ID": "ID of the quote the line item belongs to.",+ "OPPORTUNITY_ITEM_ID": "ID of the matching opportunity line item, if any.",+ "PRICEBOOK_ENTRY_ID": "ID of the price book entry for the product.",+ "CURRENCY_CODE": "Currency of the line item prices.",+ "DESCRIPTION": "Line item description.",+ "QUANTITY": "Quantity of the product.",+ "LIST_PRICE": "List price of the product.",+ "UNIT_PRICE": "Unit price charged for the product.",+ "SUBTOTAL": "Line total before discount.",+ "DISCOUNT": "Discount applied to the line item.",+ "TOTAL_PRICE": "Line total after discount.",+ "SORT_ORDER": "Position of the line item on the quote.",+ "DATE_CREATED_UTC": "UTC timestamp when the line item was created.",+ "DATE_UPDATED_UTC": "UTC timestamp when the line item was last modified (the incremental cursor).",+ "CUSTOMFIELDS": "List of custom field values defined for your Insightly account.",+ },+ },+ "Product": {+ "description": "Products in your Insightly catalog, referenced by PRODUCT_ID on price book entries.",+ "docs_url": _DOCS_URL,+ "columns": _columns(+ PRODUCT_ID="Unique identifier for the product.",+ PRODUCT_NAME="Name of the product.",+ PRODUCT_CODE="Product code.",+ PRODUCT_SKU="Product SKU.",+ PRODUCT_FAMILY="Product family the product belongs to.",+ DESCRIPTION="Product description.",+ CURRENCY_CODE="Currency of the default price.",+ DEFAULT_PRICE="Default price of the product.",+ ACTIVE="Whether the product is active.",+ ),+ },+ "Pricebook": {+ "description": "Price books that group product prices, for example per currency or market.",+ "docs_url": _DOCS_URL,+ "columns": _columns(+ PRICEBOOK_ID="Unique identifier for the price book.",+ NAME="Name of the price book.",+ DESCRIPTION="Price book description.",+ CURRENCY_CODE="Currency of the prices in the price book.",+ IS_STANDARD="Whether this is the standard price book.",+ ACTIVE="Whether the price book is active.",+ ),+ },+ "PricebookEntry": {+ "description": "The price of a product in a price book, referenced by PRICEBOOK_ENTRY_ID on opportunity and quote line items.",+ "docs_url": _DOCS_URL,+ "columns": _columns(+ PRICEBOOK_ENTRY_ID="Unique identifier for the price book entry.",+ PRICEBOOK_ID="ID of the price book the entry belongs to.",+ PRODUCT_ID="ID of the product the entry prices.",+ CURRENCY_CODE="Currency of the price.",+ PRICE="Price of the product in this price book.",+ USE_STANDARD_PRICE="Whether the entry uses the price from the standard price book.",+ ACTIVE="Whether the price book entry is active.",+ ),+ },"OpportunityStateHistory": {"description": "History of state changes (for example open, won, lost, abandoned) for each opportunity, with the reason given.","docs_url": _DOCS_URL,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/insightly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/insightly.pyindex fffa0ccedb6f..ce992d04da7a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/insightly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/insightly.py@@ -183,6 +183,8 @@ def insightly_source(# envelope, an HTML gateway page) must fail loud instead of silently syncing 0 rows."data_selector_required": True,}+ if config.params:+ endpoint_config["params"] = dict(config.params)if use_incremental:endpoint_config["incremental"] = {"start_param": UPDATED_AFTER_PARAM,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/settings.pyindex 0746c7933846..e58d8b360752 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/settings.py@@ -42,6 +42,7 @@ class InsightlyEndpointConfig:# `parent_id_field` on each row of the `fanout_parent` endpoint.fanout_parent: Optional[str] = Noneparent_id_field: Optional[str] = None+ params: dict[str, str] = field(default_factory=dict)@propertydef primary_keys(self) -> list[str]:@@ -93,12 +94,36 @@ INSIGHTLY_ENDPOINTS: dict[str, InsightlyEndpointConfig] = {"LeadSources": InsightlyEndpointConfig(name="LeadSources", path="/LeadSources", primary_key="LEAD_SOURCE_ID", partition_key=None),+ "LeadStatuses": InsightlyEndpointConfig(+ name="LeadStatuses",+ path="/LeadStatuses",+ primary_key="LEAD_STATUS_ID",+ partition_key=None,+ # The converted status is left out by default, but converted leads still reference it.+ params={"include_converted": "true"},+ ),"OpportunityLineItem": _incremental_endpoint("OpportunityLineItem","/OpportunityLineItem","OPPORTUNITY_ITEM_ID",incremental_path="/OpportunityLineItem/Search",),+ "Ticket": _incremental_endpoint("Ticket", "/Ticket", "TICKET_ID", incremental_path="/Ticket/Search"),+ "Quotation": _incremental_endpoint("Quotation", "/Quotation", "QUOTE_ID", incremental_path="/Quotation/Search"),+ "QuotationLineItem": _incremental_endpoint(+ "QuotationLineItem",+ "/QuotationLineItem",+ "QUOTATION_ITEM_ID",+ incremental_path="/QuotationLineItem/Search",+ ),+ "Product": _incremental_endpoint("Product", "/Product", "PRODUCT_ID", incremental_path="/Product/Search"),+ "Pricebook": _incremental_endpoint("Pricebook", "/Pricebook", "PRICEBOOK_ID", incremental_path="/Pricebook/Search"),+ "PricebookEntry": _incremental_endpoint(+ "PricebookEntry",+ "/PricebookEntry",+ "PRICEBOOK_ENTRY_ID",+ incremental_path="/PricebookEntry/Search",+ ),# One request per opportunity and no server-side filter, so full refresh only. History rows# carry no id of their own; a transition is identified by its opportunity, time, and state."OpportunityStateHistory": InsightlyEndpointConfig(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/tests/test_insightly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/tests/test_insightly.pyindex d972703918e8..3a94d7330829 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/tests/test_insightly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/insightly/tests/test_insightly.py@@ -247,6 +247,14 @@ class TestPagination:assert session.prepare_request.call_args.args[0].url.endswith(expected_path)assert params[0].get("updated_after_utc") == expected_filter+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_lead_statuses_include_the_converted_status(self, MockSession) -> None:+ session = MockSession.return_value+ params = _wire(session, [_response([{"LEAD_STATUS_ID": 1}])])++ _rows(_source(_make_manager(), endpoint="LeadStatuses"))+ assert params[0].get("include_converted") == "true"+@mock.patch(CLIENT_SESSION_PATCH)def test_raises_on_non_retryable_error(self, MockSession) -> None:session = MockSession.return_value