diff --git a/app/main.py b/app/main.py index 67c0153..7e9156d 100644 --- a/app/main.py +++ b/app/main.py @@ -374,13 +374,13 @@ origins = [ app.add_middleware( CORSMiddleware, - allow_origins=origins, - allow_origin_regex='https://.*\.oneskyit\.com', - allow_credentials=True, - allow_methods=['*'], - allow_headers=['*'], - #expose_headers=[], - #max_age=600, + allow_origins = origins, + allow_origin_regex = 'https://.*\.oneskyit\.com', + allow_credentials = True, + allow_methods = ['*'], + allow_headers = ['*'], + #expose_headers = [], + #max_age = 600, ) # END: CORS diff --git a/app/methods/e_cvent_methods.py b/app/methods/e_cvent_methods.py index d7c75ca..62bc648 100644 --- a/app/methods/e_cvent_methods.py +++ b/app/methods/e_cvent_methods.py @@ -14,7 +14,7 @@ from app.methods.membership_person_methods import create_membership_person_obj, app = {} app['client_id'] = '0oalt6dz82oSbN9ok1t7' # From Cvent Developer Portal -app['secret'] = 'gQY96qffZAuB_44k73C_hn_MHeByBS8LXHj1vPRm' # From Cvent Developer +app['secret'] = 'gQY96qffZAuB_44k73C_hn_MHeByBS8LXHj1vPRm' # From Cvent Developer Portal api = {} api['base_url'] = 'https://api-platform.cvent.com/ea' # Including /ea as the Cvent version. EA = Early Access @@ -109,7 +109,7 @@ def get_contact_custom_field_list(api): # Updated 2022-01-31 @logger_reset def get_contact_list(external_id: str=None, email: str=None): - log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) get_access_token() @@ -122,18 +122,38 @@ def get_contact_list(external_id: str=None, email: str=None): params = {} if external_id: + log.info(f'Looking up Cvent Contcat with External ID: {external_id}') params['filter'] = f"deleted eq 'False' and customField.609ab766-7d79-4a9d-a72c-f126412659ee eq '{external_id}'" elif email: + log.info(f'Looking up Cvent Contcat with Email: {email}') params['filter'] = f"deleted eq 'False' and email eq '{email}'" elif external_id is None: + log.info(f'Looking up Cvent Contact(s) with empty Cvent custom field for external ID.') params['filter'] = f"deleted eq 'False' and customField.609ab766-7d79-4a9d-a72c-f126412659ee lt '1'" else: + log.info(f'Looking up Cvent Contact(s) that have not been marked as deleted.') params['filter'] = f"deleted eq 'False'" - resp = requests.get(url=uri, headers=api['headers'], params=params) + try_request = True + limit = 0 + while try_request and limit < 3: + limit = limit + 1 + resp = requests.get(url=uri, headers=api['headers'], params=params) - response_data = resp.json() - log.debug(json.dumps(response_data, indent=2, default=str)) + response_data = resp.json() + log.debug(json.dumps(response_data, indent=2, default=str)) + + if 'message' in response_data and response_data['message'] == 'Too Many Requests': + log.warning('Hit Cvent rate limit. Sleeping for .5 seconds...') + time.sleep(.5) + else: + if 'paging' in response_data: + current_token = response_data.get('paging').get('currentToken') + total_count = response_data.get('paging').get('totalCount') + log.info(f'Found {total_count} results from Cvent Contact list') + log.debug(json.dumps(response_data.get('paging'), indent=2, default=str)) + + try_request = False if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False diff --git a/app/routers/e_cvent.py b/app/routers/e_cvent.py index 9aaaadf..19c4572 100644 --- a/app/routers/e_cvent.py +++ b/app/routers/e_cvent.py @@ -298,7 +298,7 @@ async def get_person_w_external_id( log.info(f'Something went wrong while trying to create or update the person in Aether based on Cvent data. Cvent (Person) Contact ID: {cvent_person_contact_id}') return mk_resp(data=None, status_code=400, response=commons.response,status_message=f'Something went wrong while trying to create or update the person in Aether based on Cvent data. Cvent (Person) Contact ID: {cvent_person_contact_id}') # Bad Request else: - log.info(f'More than one result was returned with the external ID. External ID: {email}') + log.info(f'More than one result was returned with the external ID. External ID: {external_id}') return mk_resp(data=None, status_code=400, response=commons.response) # Bad Request # ### SECTION ### Return successful results