Skip to content

Commit bd55550

Browse files
committed
added more examples
1 parent c568a05 commit bd55550

2 files changed

Lines changed: 67 additions & 2 deletions

File tree

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,71 @@ 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+
#### How to filter based on datetime
125+
126+
**Use Case**: Get profiles that have been updated between two datetimes.
127+
128+
```python
129+
klaviyo.Profiles.get_profiles(
130+
filter='less-than(updated,2023-04-26T00:00:00Z),greater-than(updated,2023-04-19T00:00:00Z)'
131+
)
132+
```
133+
134+
#### How to use pagination and the page[size] param
135+
136+
**Use Case**: Use cursor-based pagination to get the next 20 profile records.
137+
138+
```python
139+
klaviyo.Profiles.get_profiles(
140+
page_cursor="https://a.klaviyo.com/api/profiles/?page%5Bcursor%5D=bmV4dDo6aWQ6OjAxRjNaWk5ITlRYMUtFVEhQMzJTUzRBN0ZY",
141+
page_size=20
142+
)
143+
```
144+
145+
NOTE: This page cursor value is exactly what is returned in the `self`/`next`/`prev` response values
146+
147+
#### How to add additional information to your API response via additional-fields and the `includes` parameter
148+
149+
**Use Case**: Get a specific profile, return an additional predictive analytics field, and also return the list objects associated with the profile.
150+
151+
```python
152+
klaviyo.Profiles.get_profile(
153+
'01GDDKASAP8TKDDA2GRZDSVP4H',
154+
additional_fields_profile=['predictive_analytics'],
155+
include=['lists']
156+
)
157+
```
158+
159+
#### How to use our relationship endpoints to see related resources
160+
161+
**Use Case**: Get all list memberships for a profile with the given `profile_id`.
162+
163+
```python
164+
klaviyo.Profiles.get_profile_relationships_lists('01GDDKASAP8TKDDA2GRZDSVP4H')
165+
```
166+
167+
#### How to see what Klaviyo objects are associated with a specific tag
168+
169+
**Use Case**: Get all campaigns associated with the given `tag_id`.
170+
171+
```python
172+
klaviyo.Tags.get_tag_relationships_campaigns('9c8db7a0-5ab5-4e3c-9a37-a3224fd14382')
173+
```
174+
110175
## Error Handling
111176

112177
This SDK throws an `ApiException` error when the server returns a non-`2XX` response.

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]']

0 commit comments

Comments
 (0)