: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(coupa): sync purchase order and expense line tables (#103706)
Tom Owersb678ce1d04ab
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 1574ed82c1b1..173e00cee291 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@@ -2083,14 +2083,14 @@ Note: Cortex publishes an llms.txt index and every API page has a .md variant em## Coupa — **thin**-Today (8): `approvals`, `contracts`, `expense_reports`, `invoices`, `purchase_orders`, `requisitions`, `suppliers`, `users`+Today (10): `approvals`, `contracts`, `expense_lines`, `expense_reports`, `invoices`, `purchase_order_lines`, `purchase_orders`, `requisitions`, `suppliers`, `users`Diffed against: <https://compass.coupa.com/en-us/products/product-documentation/integration-technical-documentation/the-coupa-core-api/resources>-- [ ] `/invoices/{id}/lines (Invoice Line API, plus Invoice Charge / Tax Line)` — line-item grain for invoices already synced; without it spend cannot be broken down by item, account, or tax (high)-- [ ] `/purchase_orders/{id}/order_lines (Purchase Order Lines API)` — line items for POs already synced - the unit almost every spend analysis aggregates (high)-- [ ] `/requisitions/{id}/requisition_lines (Requisition Line API)` — line items behind requisitions already synced, needed for req-to-PO conversion analysis (high)-- [ ] `/expense_reports/{id}/expense_lines (Expense Lines API)` — per-line expense detail with category and allocation; expense_reports alone is only a header (high)+- [ ] `/invoices/{id}/lines (Invoice Line API, plus Invoice Charge / Tax Line)` — line-item grain for invoices already synced; without it spend cannot be broken down by item, account, or tax (high). Not buildable: the Invoice Line docs state the resource has no endpoint of its own, and Invoice Charge / Tax Line are reachable only through the invoice header response.+- [x] `/purchase_orders/{id}/order_lines (Purchase Order Lines API)` — line items for POs already synced - the unit almost every spend analysis aggregates (high) — added as `purchase_order_lines`. There is no nested path; the endpoint is the top-level `/api/purchase_order_lines`.+- [ ] `/requisitions/{id}/requisition_lines (Requisition Line API)` — line items behind requisitions already synced, needed for req-to-PO conversion analysis (high). Not buildable: `requisition-lines` is an element of the requisition response, and the Requisitions API exposes no line endpoint.+- [x] `/expense_reports/{id}/expense_lines (Expense Lines API)` — per-line expense detail with category and allocation; expense_reports alone is only a header (high) — added as `expense_lines` on the top-level `/api/expense_lines`, which covers every report in one paginated stream instead of fanning out per report.- [ ] `/accounts (plus /account_types)` — chart-of-accounts lookup that resolves the account IDs carried on every PO, invoice, and expense allocation (high)- [ ] `/commodities` — spend category lookup referenced by requisitions, POs, and invoices; the standard breakdown dimension (high)- [ ] `/departments` — lookup resolving the department IDs on users, requisitions, and approvals (high)@@ -2100,7 +2100,7 @@ Diffed against: <https://compass.coupa.com/en-us/products/product-documentation/- [ ] `Order Line Allocations and Req Line Allocation APIs` — cost-center/account splits per line - the breakdown dimension for allocated spend (medium)- [ ] `/purchase_orders/{id}/changes (Purchase Order Change / Revisions API)` — PO amendment history for change-order and cycle-time analysis (medium)-Note: Coupa Core API is very large (several hundred documented resources across Reference, Shared, and Transactional groups). PostHog exposes 8 header-level objects and no line-level or lookup tables, so nearly all analytical grain is missing. The linked doc in the payload is the legacy Compass page; the maintained index is docs.coupa.com. A GraphQL API and flat-file (CSV) export path also exist.+Note: Coupa Core API is very large (several hundred documented resources across Reference, Shared, and Transactional groups). PostHog exposes 8 header-level objects plus PO and expense lines, and no lookup tables, so most analytical grain is still missing. Coupa documents many line-level resources that have no endpoint of their own and are only reachable inside their parent object, so a gap naming a nested path is worth checking against the resource page before building it. The linked doc in the payload is the legacy Compass page; the maintained index is docs.coupa.com. A GraphQL API and flat-file (CSV) export path also exist.## Courier — gapsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/canonical_descriptions.pyindex c9f9930e54e5..184c504a6627 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/canonical_descriptions.py@@ -116,6 +116,64 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {**{"submitted-by": "The user who submitted the expense report."},),},+ "purchase_order_lines": {+ "description": "A single line item on a purchase order, at the grain most spend analysis aggregates.",+ "docs_url": "https://compass.coupa.com/en-us/products/core-applications/integrate/integrate-your-data/the-coupa-core-api",+ "columns": _columns(+ account="Account the line is charged to when there is no split billing.",+ account_allocations="Split billing allocations of the line across several accounts.",+ order_header_id="Identifier of the purchase order the line belongs to.",+ order_header_number="Purchase order number the line belongs to.",+ line_num="Position of the line within its purchase order.",+ sub_line_num="Position of the sub-line within its line.",+ description="Description of the goods or services ordered.",+ item="Catalog item ordered on the line.",+ commodity="Spend category the line is classified under.",+ supplier="Supplier the line is ordered from.",+ quantity="Quantity ordered on the line.",+ uom="Unit of measure of the ordered quantity.",+ price="Unit price of the line.",+ total="Total amount of the line.",+ currency="Currency of the line.",+ accounting_total="Line total converted to the accounting currency.",+ received="Quantity or amount received against the line.",+ invoiced="Amount invoiced against the line.",+ need_by_date="Date the ordered goods or services are needed by.",+ department="Department the line is charged to.",+ requester="User who requested the line.",+ contract="Contract the line is bought under.",+ match_type="Match level (two-way, three-way) the line is reconciled at.",+ type="Line type, for example quantity-based or amount-based.",+ ),+ },+ "expense_lines": {+ "description": "A single expense claimed on an expense report, with its category and account allocation.",+ "docs_url": "https://compass.coupa.com/en-us/products/core-applications/integrate/integrate-your-data/the-coupa-core-api",+ "columns": _columns(+ expense_report_id="Identifier of the expense report the line belongs to.",+ line_number="Position of the line within its expense report.",+ description="Description of the claimed expense.",+ expense_category="Expense category the line is classified under.",+ account="Account the expense is charged to.",+ account_allocations="Split allocations of the expense across several accounts.",+ merchant="Merchant the expense was incurred with.",+ expense_date="Date the expense was incurred.",+ amount="Amount claimed on the line.",+ currency="Currency the expense was incurred in.",+ approved_amount="Amount approved for reimbursement.",+ accounting_total="Line amount converted to the accounting currency.",+ reporting_total="Line amount converted to the reporting currency.",+ exchange_rate="Exchange rate applied to the line.",+ audit_status="Receipt audit outcome for the line.",+ requires_receipt="Whether a receipt is required for the line.",+ over_limit="Whether the line exceeds the policy limit for its category.",+ employee_reimbursable="Whether the line is reimbursable to the employee.",+ expensed_by="User the expense was incurred by.",+ expense_line_taxes="Tax amounts recorded against the line.",+ order_line_id="Purchase order line the expense is matched to.",+ type="Line type, for example a mileage, per diem, or standard expense.",+ ),+ },"users": {"description": "A user account within the Coupa instance.","docs_url": "https://compass.coupa.com/en-us/products/core-applications/integrate/integrate-your-data/the-coupa-core-api",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/settings.pyindex b25400513c67..5ee7abc7de5e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/settings.py@@ -40,6 +40,11 @@ COUPA_ENDPOINTS: dict[str, CoupaEndpointConfig] = {path="/purchase_orders",scope="core.purchase_order.read",),+ "purchase_order_lines": CoupaEndpointConfig(+ name="purchase_order_lines",+ path="/purchase_order_lines",+ scope="core.purchase_order.read",+ ),"requisitions": CoupaEndpointConfig(name="requisitions",path="/requisitions",@@ -60,6 +65,11 @@ COUPA_ENDPOINTS: dict[str, CoupaEndpointConfig] = {path="/expense_reports",scope="core.expense.read",),+ "expense_lines": CoupaEndpointConfig(+ name="expense_lines",+ path="/expense_lines",+ scope="core.expense.read",+ ),"users": CoupaEndpointConfig(name="users",path="/users",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/tests/test_coupa.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/tests/test_coupa.pyindex 6a9856154791..fdc59bdcdb19 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/tests/test_coupa.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coupa/tests/test_coupa.py@@ -12,7 +12,11 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.coupa.coupnormalize_host,validate_credentials,)-from products.warehouse_sources.backend.temporal.data_imports.sources.coupa.settings import ENDPOINTS, PAGE_SIZE+from products.warehouse_sources.backend.temporal.data_imports.sources.coupa.settings import (+ COUPA_ENDPOINTS,+ ENDPOINTS,+ PAGE_SIZE,+)_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.coupa.coupa"@@ -192,6 +196,16 @@ class TestGetRows:assert session_headers == {"Accept": "application/json"}+class TestEndpointPaths:+ @pytest.mark.parametrize("endpoint", list(ENDPOINTS))+ def test_paths_have_no_parent_placeholder(self, endpoint):+ # get_rows builds the URL by concatenation, so a nested path such as+ # /purchase_orders/{id}/order_lines would be requested verbatim. Coupa+ # exposes its line-level objects as top-level collections instead.+ assert "{" not in COUPA_ENDPOINTS[endpoint].path+ assert ":" not in COUPA_ENDPOINTS[endpoint].path++class TestCoupaSourceResponse:@pytest.mark.parametrize("endpoint", list(ENDPOINTS))def test_response_metadata_per_endpoint(self, endpoint):