Skip to content

Commit 9c1b89a

Browse files
authored
Merge pull request #22 from klaviyo/readme-examples
Added readme examples
2 parents 4749515 + 603f494 commit 9c1b89a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+337
-8711
lines changed

README.md

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Klaviyo Python SDK
22

3-
- SDK version: 2.0.1
3+
- SDK version: 2.0.2
44
- API revision: 2023-02-22
55

66
## Helpful Resources
@@ -107,6 +107,73 @@ klaviyo = KlaviyoAPI("YOUR API KEY HERE", max_delay=60, max_retries=3, test_host
107107
klaviyo.Metrics.get_metrics()
108108
```
109109

110+
### Use Case Examples
111+
112+
#### How to use filtering, sorting, and spare fieldset JSON API features
113+
114+
**Use Case**: Get events associated with a specific metric, then return just the event properties sorted by oldest to newest datetime.
115+
116+
```python
117+
klaviyo.Events.get_events(
118+
fields_event=['event_properties'],
119+
filter="equals(metric_id,\"aBc123\")",
120+
sort='-datetime'
121+
)
122+
```
123+
124+
NOTE: the filter param values need to be url-encoded
125+
126+
#### How to filter based on datetime
127+
128+
**Use Case**: Get profiles that have been updated between two datetimes.
129+
130+
```python
131+
klaviyo.Profiles.get_profiles(
132+
filter='less-than(updated,2023-04-26T00:00:00Z),greater-than(updated,2023-04-19T00:00:00Z)'
133+
)
134+
```
135+
136+
#### How to use pagination and the page[size] param
137+
138+
**Use Case**: Use cursor-based pagination to get the next 20 profile records.
139+
140+
```python
141+
klaviyo.Profiles.get_profiles(
142+
page_cursor="https://a.klaviyo.com/api/profiles/?page%5Bcursor%5D=bmV4dDo6aWQ6OjAxRjNaWk5ITlRYMUtFVEhQMzJTUzRBN0ZY",
143+
page_size=20
144+
)
145+
```
146+
147+
NOTE: This page cursor value is exactly what is returned in the `self`/`next`/`prev` response values
148+
149+
#### How to add additional information to your API response via additional-fields and the `includes` parameter
150+
151+
**Use Case**: Get a specific profile, return an additional predictive analytics field, and also return the list objects associated with the profile.
152+
153+
```python
154+
klaviyo.Profiles.get_profile(
155+
'01GDDKASAP8TKDDA2GRZDSVP4H',
156+
additional_fields_profile=['predictive_analytics'],
157+
include=['lists']
158+
)
159+
```
160+
161+
#### How to use our relationship endpoints to see related resources
162+
163+
**Use Case**: Get all list memberships for a profile with the given `profile_id`.
164+
165+
```python
166+
klaviyo.Profiles.get_profile_relationships_lists('01GDDKASAP8TKDDA2GRZDSVP4H')
167+
```
168+
169+
#### How to see what Klaviyo objects are associated with a specific tag
170+
171+
**Use Case**: Get all campaigns associated with the given `tag_id`.
172+
173+
```python
174+
klaviyo.Tags.get_tag_relationships_campaigns('9c8db7a0-5ab5-4e3c-9a37-a3224fd14382')
175+
```
176+
110177
## Error Handling
111178

112179
This SDK throws an `ApiException` error when the server returns a non-`2XX` response.
@@ -1496,9 +1563,10 @@ klaviyo.Flows.get_flow_action_flow(action_id, fields_flow=fields_flow)
14961563
# fields_flow_message | [str]
14971564
# filter | str
14981565
# page_cursor | str
1566+
# page_size | int
14991567
# sort | str
15001568

1501-
klaviyo.Flows.get_flow_action_messages(action_id, fields_flow_message=fields_flow_message, filter=filter, page_cursor=page_cursor, sort=sort)
1569+
klaviyo.Flows.get_flow_action_messages(action_id, fields_flow_message=fields_flow_message, filter=filter, page_cursor=page_cursor, page_size=page_size, sort=sort)
15021570
```
15031571

15041572

@@ -1528,9 +1596,10 @@ klaviyo.Flows.get_flow_action_relationships_flow(id)
15281596

15291597
# filter | str
15301598
# page_cursor | str
1599+
# page_size | int
15311600
# sort | str
15321601

1533-
klaviyo.Flows.get_flow_action_relationships_messages(id, filter=filter, page_cursor=page_cursor, sort=sort)
1602+
klaviyo.Flows.get_flow_action_relationships_messages(id, filter=filter, page_cursor=page_cursor, page_size=page_size, sort=sort)
15341603
```
15351604

15361605

@@ -1548,9 +1617,10 @@ klaviyo.Flows.get_flow_action_relationships_messages(id, filter=filter, page_cur
15481617
# fields_flow_action | [str]
15491618
# filter | str
15501619
# page_cursor | str
1620+
# page_size | int
15511621
# sort | str
15521622

1553-
klaviyo.Flows.get_flow_flow_actions(flow_id, fields_flow_action=fields_flow_action, filter=filter, page_cursor=page_cursor, sort=sort)
1623+
klaviyo.Flows.get_flow_flow_actions(flow_id, fields_flow_action=fields_flow_action, filter=filter, page_cursor=page_cursor, page_size=page_size, sort=sort)
15541624
```
15551625

15561626

@@ -1615,9 +1685,10 @@ klaviyo.Flows.get_flow_message_relationships_action(id)
16151685
## Keyword Arguments
16161686

16171687
# filter | str
1688+
# page_size | int
16181689
# sort | str
16191690

1620-
klaviyo.Flows.get_flow_relationships_flow_actions(id, filter=filter, sort=sort)
1691+
klaviyo.Flows.get_flow_relationships_flow_actions(id, filter=filter, page_size=page_size, sort=sort)
16211692
```
16221693

16231694

@@ -1664,9 +1735,10 @@ klaviyo.Flows.get_flow_tags(flow_id, fields_tag=fields_tag)
16641735
# filter | str
16651736
# include | [str]
16661737
# page_cursor | str
1738+
# page_size | int
16671739
# sort | str
16681740

1669-
klaviyo.Flows.get_flows(fields_flow_action=fields_flow_action, fields_flow=fields_flow, filter=filter, include=include, page_cursor=page_cursor, sort=sort)
1741+
klaviyo.Flows.get_flows(fields_flow_action=fields_flow_action, fields_flow=fields_flow, filter=filter, include=include, page_cursor=page_cursor, page_size=page_size, sort=sort)
16701742
```
16711743

16721744

@@ -1920,11 +1992,7 @@ klaviyo.Metrics.query_metric_aggregates(body)
19201992

19211993
# body | dict
19221994

1923-
## Keyword Arguments
1924-
1925-
# additional_fields_profile | [str]
1926-
1927-
klaviyo.Profiles.create_profile(body, additional_fields_profile=additional_fields_profile)
1995+
klaviyo.Profiles.create_profile(body)
19281996
```
19291997

19301998

@@ -2021,10 +2089,10 @@ klaviyo.Profiles.get_profile_segments(profile_id, fields_segment=fields_segment)
20212089
# fields_profile | [str]
20222090
# filter | str
20232091
# page_cursor | str
2024-
# sort | str
20252092
# page_size | int
2093+
# sort | str
20262094

2027-
klaviyo.Profiles.get_profiles(additional_fields_profile=additional_fields_profile, fields_profile=fields_profile, filter=filter, page_cursor=page_cursor, sort=sort, page_size=page_size)
2095+
klaviyo.Profiles.get_profiles(additional_fields_profile=additional_fields_profile, fields_profile=fields_profile, filter=filter, page_cursor=page_cursor, page_size=page_size, sort=sort)
20282096
```
20292097

20302098

klaviyo_api/wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ class KlaviyoAPI:
3232

3333
_REVISION = "2023-02-22"
3434

35+
_STATUS_CODE_CONNECTION_RESET_BY_PEER = 104
3536
_STATUS_CODE_TOO_MANY_REQUESTS = 429
3637
_STATUS_CODE_SERVICE_UNAVAILABLE = 503
3738
_STATUS_CODE_GATEWAY_TIMEOUT = 504
3839
_STATUS_CODE_A_TIMEOUT_OCCURED = 524
39-
_STATUS_CODE_CONNECTION_RESET_BY_PEER = 104
4040

4141
_RETRY_CODES = {
42+
_STATUS_CODE_CONNECTION_RESET_BY_PEER,
4243
_STATUS_CODE_TOO_MANY_REQUESTS,
4344
_STATUS_CODE_SERVICE_UNAVAILABLE,
4445
_STATUS_CODE_GATEWAY_TIMEOUT,
4546
_STATUS_CODE_A_TIMEOUT_OCCURED,
46-
_STATUS_CODE_CONNECTION_RESET_BY_PEER
4747
}
4848

4949
_CURSOR_SEARCH_TOKENS = ['page%5Bcursor%5D','page[cursor]']

openapi_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313

14-
__version__ = "2.0.1"
14+
__version__ = "2.0.2"
1515

1616
# import ApiClient
1717
from openapi_client.api_client import ApiClient

openapi_client/api/campaigns_api.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def create_campaign(
11581158
):
11591159
"""Create Campaign # noqa: E501
11601160
1161-
Creates a campaign given a set of parameters, then returns it.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
1161+
Creates a campaign given a set of parameters, then returns it.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
11621162
This method makes a synchronous HTTP request by default. To make an
11631163
asynchronous HTTP request, please pass async_req=True
11641164
@@ -1241,7 +1241,7 @@ def create_campaign_clone(
12411241
):
12421242
"""Create Campaign Clone # noqa: E501
12431243
1244-
Clones an existing campaign, returning a new campaign based on the original with a new ID and name.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
1244+
Clones an existing campaign, returning a new campaign based on the original with a new ID and name.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
12451245
This method makes a synchronous HTTP request by default. To make an
12461246
asynchronous HTTP request, please pass async_req=True
12471247
@@ -1324,7 +1324,7 @@ def create_campaign_message_assign_template(
13241324
):
13251325
"""Assign Campaign Message Template # noqa: E501
13261326
1327-
Creates a non-reusable version of the template and assigns it to the message.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
1327+
Creates a non-reusable version of the template and assigns it to the message.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
13281328
This method makes a synchronous HTTP request by default. To make an
13291329
asynchronous HTTP request, please pass async_req=True
13301330
@@ -1407,7 +1407,7 @@ def create_campaign_recipient_estimation_job(
14071407
):
14081408
"""Create Campaign Recipient Estimation Job # noqa: E501
14091409
1410-
Trigger an asynchronous job to update the estimated number of recipients for the given campaign ID. Use the `Get Campaign Recipient Estimation Job` endpoint to retrieve the status of this estimation job. Use the `Get Campaign Recipient Estimation` endpoint to retrieve the estimated recipient count for a given campaign.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
1410+
Trigger an asynchronous job to update the estimated number of recipients for the given campaign ID. Use the `Get Campaign Recipient Estimation Job` endpoint to retrieve the status of this estimation job. Use the `Get Campaign Recipient Estimation` endpoint to retrieve the estimated recipient count for a given campaign.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
14111411
This method makes a synchronous HTTP request by default. To make an
14121412
asynchronous HTTP request, please pass async_req=True
14131413
@@ -1490,7 +1490,7 @@ def create_campaign_send_job(
14901490
):
14911491
"""Create Campaign Send Job # noqa: E501
14921492
1493-
Trigger a campaign to send asynchronously<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
1493+
Trigger a campaign to send asynchronously<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
14941494
This method makes a synchronous HTTP request by default. To make an
14951495
asynchronous HTTP request, please pass async_req=True
14961496
@@ -1573,7 +1573,7 @@ def delete_campaign(
15731573
):
15741574
"""Delete Campaign # noqa: E501
15751575
1576-
Delete a campaign with the given campaign ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
1576+
Delete a campaign with the given campaign ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
15771577
This method makes a synchronous HTTP request by default. To make an
15781578
asynchronous HTTP request, please pass async_req=True
15791579
@@ -1656,7 +1656,7 @@ def get_campaign(
16561656
):
16571657
"""Get Campaign # noqa: E501
16581658
1659-
Returns a specific campaign based on a required id.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Read` # noqa: E501
1659+
Returns a specific campaign based on a required id.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:read` # noqa: E501
16601660
This method makes a synchronous HTTP request by default. To make an
16611661
asynchronous HTTP request, please pass async_req=True
16621662
@@ -1742,7 +1742,7 @@ def get_campaign_message(
17421742
):
17431743
"""Get Campaign Message # noqa: E501
17441744
1745-
Returns a specific message based on a required id.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Read` # noqa: E501
1745+
Returns a specific message based on a required id.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:read` # noqa: E501
17461746
This method makes a synchronous HTTP request by default. To make an
17471747
asynchronous HTTP request, please pass async_req=True
17481748
@@ -1826,7 +1826,7 @@ def get_campaign_recipient_estimation(
18261826
):
18271827
"""Get Campaign Recipient Estimation # noqa: E501
18281828
1829-
Get the estimated recipient count for a campaign with the provided campaign ID. You can refresh this count by using the `Create Campaign Recipient Estimation Job` endpoint.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Read` # noqa: E501
1829+
Get the estimated recipient count for a campaign with the provided campaign ID. You can refresh this count by using the `Create Campaign Recipient Estimation Job` endpoint.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:read` # noqa: E501
18301830
This method makes a synchronous HTTP request by default. To make an
18311831
asynchronous HTTP request, please pass async_req=True
18321832
@@ -1910,7 +1910,7 @@ def get_campaign_recipient_estimation_job(
19101910
):
19111911
"""Get Campaign Recipient Estimation Job # noqa: E501
19121912
1913-
Retrieve the status of a recipient estimation job triggered with the `Create Campaign Recipient Estimation Job` endpoint.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Read` # noqa: E501
1913+
Retrieve the status of a recipient estimation job triggered with the `Create Campaign Recipient Estimation Job` endpoint.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:read` # noqa: E501
19141914
This method makes a synchronous HTTP request by default. To make an
19151915
asynchronous HTTP request, please pass async_req=True
19161916
@@ -1994,7 +1994,7 @@ def get_campaign_relationships_tags(
19941994
):
19951995
"""Get Campaign Relationships Tags # noqa: E501
19961996
1997-
Returns the IDs of all tags associated with the given campaign.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `Campaigns Read` `Tags Read` # noqa: E501
1997+
Returns the IDs of all tags associated with the given campaign.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `campaigns:read` `tags:read` # noqa: E501
19981998
This method makes a synchronous HTTP request by default. To make an
19991999
asynchronous HTTP request, please pass async_req=True
20002000
@@ -2077,7 +2077,7 @@ def get_campaign_send_job(
20772077
):
20782078
"""Get Campaign Send Job # noqa: E501
20792079
2080-
Get a campaign send job<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Read` # noqa: E501
2080+
Get a campaign send job<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:read` # noqa: E501
20812081
This method makes a synchronous HTTP request by default. To make an
20822082
asynchronous HTTP request, please pass async_req=True
20832083
@@ -2161,7 +2161,7 @@ def get_campaign_tags(
21612161
):
21622162
"""Get Campaign Tags # noqa: E501
21632163
2164-
Return all tags that belong to the given campaign.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `Campaigns Read` `Tags Read` # noqa: E501
2164+
Return all tags that belong to the given campaign.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` **Scopes:** `campaigns:read` `tags:read` # noqa: E501
21652165
This method makes a synchronous HTTP request by default. To make an
21662166
asynchronous HTTP request, please pass async_req=True
21672167
@@ -2244,7 +2244,7 @@ def get_campaigns(
22442244
):
22452245
"""Get Campaigns # noqa: E501
22462246
2247-
Returns some or all campaigns based on [optional] filters<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Read` # noqa: E501
2247+
Returns some or all campaigns based on [optional] filters<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:read` # noqa: E501
22482248
This method makes a synchronous HTTP request by default. To make an
22492249
asynchronous HTTP request, please pass async_req=True
22502250
@@ -2330,7 +2330,7 @@ def update_campaign(
23302330
):
23312331
"""Update Campaign # noqa: E501
23322332
2333-
Update a campaign with the given campaign ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
2333+
Update a campaign with the given campaign ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
23342334
This method makes a synchronous HTTP request by default. To make an
23352335
asynchronous HTTP request, please pass async_req=True
23362336
@@ -2417,7 +2417,7 @@ def update_campaign_message(
24172417
):
24182418
"""Update Campaign Message # noqa: E501
24192419
2420-
Update a campaign message<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
2420+
Update a campaign message<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
24212421
This method makes a synchronous HTTP request by default. To make an
24222422
asynchronous HTTP request, please pass async_req=True
24232423
@@ -2504,7 +2504,7 @@ def update_campaign_send_job(
25042504
):
25052505
"""Update Campaign Send Job # noqa: E501
25062506
2507-
Permanently cancel the campaign, setting the status to CANCELED or revert the campaign, setting the status back to DRAFT<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `Campaigns Write` # noqa: E501
2507+
Permanently cancel the campaign, setting the status to CANCELED or revert the campaign, setting the status back to DRAFT<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `campaigns:write` # noqa: E501
25082508
This method makes a synchronous HTTP request by default. To make an
25092509
asynchronous HTTP request, please pass async_req=True
25102510

0 commit comments

Comments
 (0)