Skip to content

Commit

Permalink
fix: be defensive about pulling external_id from braze export
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Jan 25, 2024
1 parent 9e7a0d9 commit 5a1f485
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[0.2.1]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fix: be defensive about pulling external_id from braze export.

[0.2.0]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
feat: check for external ids in batchs when creating aliases.
Expand Down
2 changes: 1 addition & 1 deletion braze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Python client for interacting with Braze APIs.
"""

__version__ = '0.2.0'
__version__ = '0.2.1'
9 changes: 6 additions & 3 deletions braze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_braze_external_id(self, email):
}
response = self._make_request(payload, BrazeAPIEndpoints.EXPORT_IDS, REQUEST_TYPE_POST)
if response['users'] and 'external_id' in response['users'][0]:
return response['users'][0]['external_id']
return response['users'][0].get('external_id')

return None

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

for identified_user in response['users']:
external_ids_by_email[identified_user['email']] = identified_user['external_id']
external_ids_by_email[identified_user['email']] = identified_user.get('external_id')

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

0 comments on commit 5a1f485

Please sign in to comment.