Skip to content

Commit 82628eb

Browse files
feat(ds): shopify endpoint beta (#41933)
1 parent 0b1c02e commit 82628eb

File tree

7 files changed

+446
-51
lines changed

7 files changed

+446
-51
lines changed

posthog/temporal/data_imports/sources/shopify/constants.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from .queries.collections import COLLECTIONS_QUERY
66
from .queries.customers import CUSTOMERS_QUERY
77
from .queries.discount_nodes import DISCOUNT_NODES_QUERY
8+
from .queries.orders import ORDERS_QUERY
9+
from .queries.products import PRODUCTS_QUERY
810
from .utils import ShopifyGraphQLObject
911

1012
SHOPIFY_API_VERSION = "2025-10"
@@ -36,6 +38,9 @@
3638
SHOP = "shop"
3739
SUBSCRIPTION_CONTRACTS = "subscriptionContracts"
3840

41+
# graphql will reject the orders endpoint query for "complexity cost" if the page size is above ~35
42+
SHOPIFY_PAGE_SIZE_OVERRIDES = {ORDERS: 20}
43+
3944

4045
# NOTE: some of the permissions queries may seem random. not every field on a given graphql object
4146
# have the same access requirements
@@ -76,6 +81,16 @@
7681
display_name="discountCodes",
7782
permissions_query="{ discountNodes(first: 1) { nodes { id } } }",
7883
),
84+
ORDERS: ShopifyGraphQLObject(
85+
name=ORDERS,
86+
query=ORDERS_QUERY,
87+
permissions_query="{ orders(first: 1) { nodes { id } } }",
88+
),
89+
PRODUCTS: ShopifyGraphQLObject(
90+
name=PRODUCTS,
91+
query=PRODUCTS_QUERY,
92+
permissions_query="{ products(first: 1) { nodes { id } } }",
93+
),
7994
}
8095

8196

posthog/temporal/data_imports/sources/shopify/queries/abandoned_checkouts.py

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from .fragments import KV_FRAGMENT, MAILING_ADDRESS_FRAGMENT, MONEY_BAG_FRAGMENT
1+
from .fragments import CUSTOMER_FRAGMENT, KV_FRAGMENT, MAILING_ADDRESS_FRAGMENT, MONEY_BAG_FRAGMENT
22

33
ABANDONED_CHECKOUTS_SORTKEY = "CREATED_AT"
44

55
# NOTE: 250 is the max allowable query size for line items
6+
# NOTE lineItems in abandonedCheckouts are not the same as the LineItem object
67
ABANDONED_CHECKOUTS_QUERY = f"""
78
query PaginatedAbandonedCheckouts($pageSize: Int!, $cursor: String, $query: String) {{
89
abandonedCheckouts(
@@ -15,55 +16,7 @@
1516
completedAt
1617
createdAt
1718
customAttributes {KV_FRAGMENT}
18-
customer {{
19-
addresses {MAILING_ADDRESS_FRAGMENT}
20-
amountSpent {{
21-
amount
22-
currencyCode
23-
}}
24-
createdAt
25-
defaultAddress {MAILING_ADDRESS_FRAGMENT}
26-
defaultEmailAddress {{
27-
emailAddress
28-
marketingOptInLevel
29-
marketingState
30-
marketingUpdatedAt
31-
openTrackingLevel
32-
validFormat
33-
}}
34-
defaultPhoneNumber {{
35-
marketingCollectedFrom
36-
marketingOptInLevel
37-
marketingState
38-
marketingUpdatedAt
39-
phoneNumber
40-
}}
41-
displayName
42-
firstName
43-
id
44-
lastName
45-
lastOrder {{
46-
id
47-
name
48-
}}
49-
legacyResourceId
50-
lifetimeDuration
51-
locale
52-
multipassIdentifier
53-
note
54-
numberOfOrders
55-
productSubscriberStatus
56-
state
57-
statistics {{
58-
predictedSpendTier
59-
rfmGroup
60-
}}
61-
tags
62-
taxExempt
63-
taxExemptions
64-
updatedAt
65-
verifiedEmail
66-
}}
19+
customer {CUSTOMER_FRAGMENT}
6720
discountCodes
6821
id
6922
lineItems(first: 250) {{

posthog/temporal/data_imports/sources/shopify/queries/fragments.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
ID_NAME_FRAGMENT = """{
2+
id
3+
name
4+
}"""
5+
6+
ID_NAME_CREATED_FRAGMENT = """{
7+
id
8+
name
9+
createdAt
10+
}"""
11+
12+
ID_NAME_CREATED_UPDATED_FRAGMENT = """{
13+
id
14+
name
15+
createdAt
16+
updatedAt
17+
}"""
18+
19+
ID_TITLE_CREATED_UPDATED_FRAGMENT = """{
20+
id
21+
title
22+
createdAt
23+
updatedAt
24+
}"""
25+
126
NODE_CONNECTION_ID_FRAGMENT = """{
227
nodes {
328
id
@@ -18,11 +43,19 @@
1843
validFormat
1944
}"""
2045

46+
FULFILLMENT_FRAGMENT = """{
47+
id
48+
name
49+
createdAt
50+
updatedAt
51+
}"""
52+
2153
KV_FRAGMENT = """{
2254
key
2355
value
2456
}"""
2557

58+
2659
MAILING_ADDRESS_FRAGMENT = """{
2760
address1
2861
address2
@@ -79,3 +112,73 @@
79112
marketingUpdatedAt
80113
phoneNumber
81114
}"""
115+
116+
TAX_LINES_FRAGMENT = f"""{{
117+
priceSet {MONEY_BAG_FRAGMENT}
118+
rate
119+
ratePercentage
120+
source
121+
title
122+
}}"""
123+
124+
LINE_ITEM_FRAGMENT = f"""{{
125+
id
126+
currentQuantity
127+
customAttributes {KV_FRAGMENT}
128+
discountedTotalSet {MONEY_BAG_FRAGMENT}
129+
discountedUnitPriceSet {MONEY_BAG_FRAGMENT}
130+
isGiftCard
131+
name
132+
nonFulfillableQuantity
133+
originalTotalSet {MONEY_BAG_FRAGMENT}
134+
originalUnitPriceSet {MONEY_BAG_FRAGMENT}
135+
product {{
136+
id
137+
}}
138+
quantity
139+
refundableQuantity
140+
requiresShipping
141+
restockable
142+
sku
143+
taxable
144+
taxLines(first: 250) {TAX_LINES_FRAGMENT}
145+
title
146+
totalDiscountSet {MONEY_BAG_FRAGMENT}
147+
unfulfilledDiscountedTotalSet {MONEY_BAG_FRAGMENT}
148+
unfulfilledOriginalTotalSet {MONEY_BAG_FRAGMENT}
149+
unfulfilledQuantity
150+
variant {{
151+
id
152+
}}
153+
vendor
154+
}}"""
155+
156+
CUSTOMER_FRAGMENT = f"""{{
157+
addresses {MAILING_ADDRESS_FRAGMENT}
158+
amountSpent {MONEY_V2_FRAGMENT}
159+
createdAt
160+
defaultAddress {MAILING_ADDRESS_FRAGMENT}
161+
defaultEmailAddress {EMAIL_ADDRESS_FRAGMENT}
162+
defaultPhoneNumber {PHONE_NUMBER_FRAGMENT}
163+
displayName
164+
firstName
165+
id
166+
lastName
167+
lastOrder {ID_NAME_FRAGMENT}
168+
lifetimeDuration
169+
locale
170+
multipassIdentifier
171+
note
172+
numberOfOrders
173+
productSubscriberStatus
174+
state
175+
statistics {{
176+
predictedSpendTier
177+
rfmGroup
178+
}}
179+
tags
180+
taxExempt
181+
taxExemptions
182+
updatedAt
183+
verifiedEmail
184+
}}"""

0 commit comments

Comments
 (0)