Skip to content

Commit 5a1f485

Browse files
committed
fix: be defensive about pulling external_id from braze export
1 parent 9e7a0d9 commit 5a1f485

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Change Log
1414
Unreleased
1515
~~~~~~~~~~
1616

17+
[0.2.1]
18+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
fix: be defensive about pulling external_id from braze export.
20+
1721
[0.2.0]
1822
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1923
feat: check for external ids in batchs when creating aliases.

braze/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Python client for interacting with Braze APIs.
33
"""
44

5-
__version__ = '0.2.0'
5+
__version__ = '0.2.1'

braze/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def get_braze_external_id(self, email):
135135
}
136136
response = self._make_request(payload, BrazeAPIEndpoints.EXPORT_IDS, REQUEST_TYPE_POST)
137137
if response['users'] and 'external_id' in response['users'][0]:
138-
return response['users'][0]['external_id']
138+
return response['users'][0].get('external_id')
139139

140140
return None
141141

@@ -147,7 +147,10 @@ def get_braze_external_id_batch(self, emails, alias_label):
147147
https://www.braze.com/docs/api/endpoints/export/user_data/post_users_identifier/
148148
"Up to 50 external_ids or user_aliases can be included in a single request.
149149
Should you want to specify device_id or email_address
150-
only one of either identifier can be included per request."
150+
only one of either identifier can be included per request.
151+
[...]
152+
if a field is missing from the object it should be assumed to be null, false, or empty
153+
"
151154
152155
Arguments:
153156
emails (list(str)): e.g. ['test1@example.com', 'test1@example.com']
@@ -174,7 +177,7 @@ def get_braze_external_id_batch(self, emails, alias_label):
174177
response = self._make_request(payload, BrazeAPIEndpoints.EXPORT_IDS, REQUEST_TYPE_POST)
175178

176179
for identified_user in response['users']:
177-
external_ids_by_email[identified_user['email']] = identified_user['external_id']
180+
external_ids_by_email[identified_user['email']] = identified_user.get('external_id')
178181

179182
logger.info(f'external ids from batch identify braze users response: {external_ids_by_email}')
180183
return external_ids_by_email

0 commit comments

Comments
 (0)