Working on Cvent API for IDAA members. Adding and updating a person along with membership info now works. Updating the membership status for person and user tables now works.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
from __future__ import annotations
|
||||
import datetime, pprint, pytz, random, requests
|
||||
import datetime, pprint, pytz, random, requests, time
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||
from app.lib_general import log, logging
|
||||
from app.lib_general import log, logging, logger_reset
|
||||
|
||||
from app.methods.person_methods import get_person_rec_w_external_id, load_person_obj, update_person_kiss
|
||||
|
||||
@@ -20,9 +20,10 @@ api['base_url'] = 'https://api-platform.cvent.com/ea' # Including /ea as the Cve
|
||||
api['headers'] = {} # { 'Content-Type': content_type, 'Authorization': 'Basic '+str(cvent_authorization_base64) }
|
||||
|
||||
|
||||
# def get_access_token(api, app):
|
||||
# Updated 2022-02-01
|
||||
@logger_reset
|
||||
def get_access_token():
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
log.debug(f'API data:\n{api}')
|
||||
@@ -85,6 +86,8 @@ def get_access_token():
|
||||
return api
|
||||
|
||||
|
||||
# Updated 2022-01-31
|
||||
@logger_reset
|
||||
def get_contact_custom_field_list(api):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
@@ -110,7 +113,9 @@ def get_contact_custom_field_list(api):
|
||||
return response_data
|
||||
|
||||
|
||||
def get_contact_list(api, external_id=False):
|
||||
# Updated 2022-01-31
|
||||
@logger_reset
|
||||
def get_contact_list(api, external_id: str=False):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -140,8 +145,9 @@ def get_contact_list(api, external_id=False):
|
||||
return response_data
|
||||
|
||||
|
||||
# def get_contact_id(api, contact_id):
|
||||
def get_contact_id(contact_id):
|
||||
# Updated 2022-02-01
|
||||
@logger_reset
|
||||
def get_contact_id(contact_id: str):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -149,6 +155,9 @@ def get_contact_id(contact_id):
|
||||
# else: get_access_token()
|
||||
get_access_token()
|
||||
|
||||
log.warning('Sleeping for 1 second to avoid Cvent rate limit...')
|
||||
time.sleep(1)
|
||||
|
||||
endpoint = f'/contacts/{contact_id}'
|
||||
uri = api['base_url']+endpoint
|
||||
|
||||
@@ -167,3 +176,43 @@ def get_contact_id(contact_id):
|
||||
# f.write(pprint.pformat(response_data, indent=2, width=160))
|
||||
|
||||
return response_data
|
||||
|
||||
|
||||
# Updated 2022-02-01
|
||||
@logger_reset
|
||||
def modify_contact_id(contact_id: str, field_list: list=[], custom_field_id: str=None, custom_field_value: str=None):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
get_access_token()
|
||||
|
||||
if custom_field_id:
|
||||
endpoint = f'/contacts/{contact_id}/custom-fields/{custom_field_id}/answers'
|
||||
elif field_list:
|
||||
endpoint = f'/contacts/{contact_id}'
|
||||
else:
|
||||
log.error('Missing required parameters')
|
||||
return False
|
||||
uri = api['base_url']+endpoint
|
||||
|
||||
params = {}
|
||||
|
||||
data = {}
|
||||
if custom_field_id:
|
||||
data['id'] = custom_field_id
|
||||
data['value'] = custom_field_value
|
||||
else:
|
||||
data = field_list
|
||||
data['id'] = contact_id
|
||||
|
||||
if custom_field_id:
|
||||
resp = requests.put(url=uri, headers=api['headers'], params=params, json=data)
|
||||
else:
|
||||
resp = requests.patch(url=uri, headers=api['headers'], params=params, json=data)
|
||||
|
||||
response_data = resp.json()
|
||||
log.debug(response_data)
|
||||
|
||||
if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False
|
||||
|
||||
return response_data
|
||||
|
||||
@@ -4,7 +4,7 @@ import datetime, json
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.lib_general import log, logging
|
||||
from app.lib_general import log, logging, logger_reset
|
||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_insert_or_update, sql_select, sql_update
|
||||
|
||||
from app.methods.membership_cfg_methods import load_membership_cfg_obj
|
||||
@@ -22,6 +22,7 @@ from app.models.membership_person_models import Membership_Person_Base
|
||||
|
||||
# ### BEGIN ### API Membership Person Methods ### load_membership_person_obj() ###
|
||||
# Updated 2022-01-11
|
||||
@logger_reset
|
||||
def load_membership_person_obj(
|
||||
membership_person_id: int|str,
|
||||
limit: int = 100,
|
||||
@@ -50,7 +51,7 @@ def load_membership_person_obj(
|
||||
inc_product_list: bool = False, # The list of products that give access to a member_type or member_group
|
||||
# inc_user: bool = False,
|
||||
) -> Membership_Person_Base:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if membership_person_id := redis_lookup_id_random(record_id_random=membership_person_id, table_name='membership_person'): pass
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||
from app.lib_general import log, logging
|
||||
from app.lib_general import log, logging, logger_reset
|
||||
# from app.methods.membership_person_methods import get_membership_person_rec_list, load_membership_person_obj
|
||||
from app.methods.membership_cfg_methods import load_membership_cfg_obj
|
||||
from app.methods.product_methods import get_product_rec_list, load_product_obj
|
||||
@@ -16,6 +16,7 @@ from app.models.membership_person_type_models import Membership_Person_Type_Base
|
||||
|
||||
# ### BEGIN ### API Membership Type Person Methods ### load_membership_person_type_obj() ###
|
||||
# Updated 2021-07-09
|
||||
@logger_reset
|
||||
def load_membership_person_type_obj(
|
||||
membership_person_type_id: int|str,
|
||||
limit: int = 1000,
|
||||
@@ -36,7 +37,7 @@ def load_membership_person_type_obj(
|
||||
inc_product_list: bool = False,
|
||||
inc_person: bool = False,
|
||||
) -> Membership_Person_Type_Base|bool:
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if membership_person_type_id := redis_lookup_id_random(record_id_random=membership_person_type_id, table_name='membership_person_type'): pass
|
||||
|
||||
@@ -624,7 +624,7 @@ def get_person_rec_list(
|
||||
limit: int = 1000,
|
||||
offset: int = 0,
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
||||
|
||||
Reference in New Issue
Block a user