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
|
||||
|
||||
Reference in New Issue
Block a user