327 lines
10 KiB
Python
327 lines
10 KiB
Python
import datetime, json, pprint, pytz, random, requests, string, time
|
|
|
|
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, logger_reset
|
|
|
|
|
|
headers = { 'Content-Type': 'application/json;charset=UTF-8' }
|
|
|
|
app = {}
|
|
app['user_email'] = 'oneskyit_integration@oneskyit.com'
|
|
app['user_password'] = 'dAPpHDE6d5vLHjsk'
|
|
|
|
app['name'] = 'IshltOneSkyITLIVE'
|
|
app['key'] = '98yp4fa57mJX6nU4'
|
|
app['id'] = 'IshltOneSkyITLIVE'
|
|
app['password'] = '98yp4fa57mJX6nU4'
|
|
log.debug('App data', app)
|
|
|
|
api = {}
|
|
api['base_url'] = 'https://public.impexium.com/Api/v1' # or https://ishlt.mpxapi.com:443/api/v1 ??
|
|
api['headers'] = { 'Content-Type': 'application/json;charset=UTF-8' }
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_access_token() ###
|
|
# Updated 2022-02-18
|
|
@logger_reset
|
|
def get_access_token(api, app):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
log.debug(f'API data:\n{api}')
|
|
|
|
endpoint = '/WebApiUrl'
|
|
uri = api['base_url']+endpoint
|
|
|
|
data = { 'AppName': app['name'], 'AppKey': app['key'] }
|
|
|
|
resp = requests.post(url=uri, json=data, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
log.debug(json.dumps(response_data, indent=2, default=str))
|
|
|
|
api['access_token'] = response_data['accessToken']
|
|
api['headers']['AccessToken'] = response_data['accessToken']
|
|
api['auth_uri'] = response_data['uri']
|
|
|
|
log.debug(api)
|
|
|
|
return api
|
|
# ### END ### API External Impexium Methods ### get_access_token() ###
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### authenticate() ###
|
|
# Updated 2022-02-18
|
|
@logger_reset
|
|
def authenticate(api, app):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
data = { 'AppId': app['id'], 'AppPassword': app['password'], 'AppUserEmail': app['user_email'], 'AppUserPassword': app['user_password'] }
|
|
|
|
resp = requests.post(url=api['auth_uri'], json=data, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
api['headers']['AppToken'] = response_data['appToken']
|
|
api['headers']['UserToken'] = response_data['userToken']
|
|
api['base_url'] = response_data['uri']
|
|
|
|
# app['user_id'] = response_data['userId']
|
|
# app['sso_token'] = response_data['ssoToken']
|
|
# app['app_configuration'] = response_data['appConfiguration'] # allowGoogleLogin=False, allowLinkedInLogin=False
|
|
|
|
log.debug(api)
|
|
|
|
return api
|
|
# ### END ### API External Impexium Methods ### authenticate() ###
|
|
|
|
|
|
api = get_access_token(api=api, app=app)
|
|
log.debug(api)
|
|
|
|
api = authenticate(api=api, app=app)
|
|
log.debug(api)
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_custom_fields() ###
|
|
# Updated 2022-02-18
|
|
@logger_reset
|
|
def get_custom_fields(api, name=None, page=1):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
endpoint = f'/Setup/customfields/{page}'
|
|
uri = api['base_url']+endpoint
|
|
|
|
print('Endpoint URI', uri)
|
|
|
|
params = {}
|
|
|
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
custom_field_li = response_data
|
|
|
|
return custom_field_li
|
|
# ### END ### API External Impexium Methods ### get_custom_fields() ###
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_events() ###
|
|
# Updated 2022-02-18
|
|
@logger_reset
|
|
def get_events(page=1):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
endpoint = f'/Events/All/{page}'
|
|
uri = api['base_url']+endpoint
|
|
|
|
print('Endpoint URI', uri)
|
|
|
|
params = {}
|
|
|
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
# pp = pprint.PrettyPrinter(indent=2)
|
|
# pp.pprint(response_data)
|
|
# print('**************************')
|
|
|
|
event_li = response_data
|
|
|
|
return event_li
|
|
# ### END ### API External Impexium Methods ### get_events() ###
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_event_registrants() ###
|
|
# Updated 2021-10-07
|
|
def get_event_registrants(
|
|
event_code: str,
|
|
page: int = 1,
|
|
return_all: bool = False
|
|
):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
endpoint = f'/Events/{event_code}/Registrations/{page}'
|
|
uri = api['base_url']+endpoint
|
|
|
|
params = {}
|
|
|
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
# pp = pprint.PrettyPrinter(indent=2)
|
|
# pp.pprint(response_data)
|
|
# print(response_data)
|
|
# print('**************************')
|
|
|
|
event_registrant_li = response_data
|
|
if return_all:
|
|
return event_registrant_li
|
|
else:
|
|
return event_registrant_li['dataList']
|
|
# ### END ### API Impexium Methods ### get_event_registrants() ###
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_individual_registrations() ###
|
|
# Updated 2022-02-18
|
|
def get_individual_registrations(api, record_number, event_code=None, page=1):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
endpoint = f'/Individuals/{record_number}/Registrations/{page}'
|
|
uri = api['base_url']+endpoint
|
|
|
|
params = { 'eventCode': event_code }
|
|
|
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
# pp = pprint.PrettyPrinter(indent=2)
|
|
# pp.pprint(response_data)
|
|
# print('**************************')
|
|
|
|
individual_registraion_li = response_data
|
|
|
|
return individual_registraion_li
|
|
# ### END ### API External Impexium Methods ### get_individual_registrations() ###
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_individual_purchases() ###
|
|
# Updated 2022-02-18
|
|
def get_individual_purchases(api, record_number, product_code=None, purchased_since=None, product_category_code=None, page=1):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
endpoint = f'/Individuals/{record_number}/Purchases/{page}'
|
|
uri = api['base_url']+endpoint
|
|
|
|
params = { 'productCode': product_code, 'purchasedSince': purchased_since, 'productCategoryCode': product_category_code }
|
|
|
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
# pp = pprint.PrettyPrinter(indent=2)
|
|
# pp.pprint(response_data)
|
|
# print('**************************')
|
|
|
|
individual_purchase_li = response_data
|
|
|
|
return individual_purchase_li
|
|
# ### END ### API External Impexium Methods ### get_individual_purchases() ###
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_individual_custom_fields() ###
|
|
# Updated 2022-02-18
|
|
def get_individual_custom_fields(api, individual_id):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
endpoint = f'/Individuals/{individual_id}/CustomFields'
|
|
uri = api['base_url']+endpoint
|
|
|
|
params = { }
|
|
|
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
# pp = pprint.PrettyPrinter(indent=2)
|
|
# pp.pprint(response_data)
|
|
# print('**************************')
|
|
|
|
individual_custom_field_li = response_data
|
|
|
|
return individual_custom_field_li
|
|
# ### END ### API External Impexium Methods ### get_individual_custom_fields() ###
|
|
|
|
|
|
# ### BEGIN ### API External Impexium Methods ### get_individual_orders_open() ###
|
|
# Updated 2022-02-18
|
|
def get_individual_orders_open(api, record_number, include_line_items=False, from_date=None, to_date=None, page=1):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
endpoint = f'/Individuals/{record_number}/Orders/Open/{page}'
|
|
uri = api['base_url']+endpoint
|
|
print(uri)
|
|
|
|
params = { 'includeLineItems': include_line_items, 'fromDate': from_date, 'toDate': to_date }
|
|
|
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
|
|
|
log.debug('Status Code:', resp.status_code)
|
|
log.debug('Headers:', resp.headers)
|
|
# log.debug('Encoding:', resp.encoding)
|
|
log.debug('JSON:', resp.json())
|
|
# log.debug('Text:', resp.text)
|
|
|
|
response_data = resp.json()
|
|
|
|
# pp = pprint.PrettyPrinter(indent=2)
|
|
# pp.pprint(response_data)
|
|
# print('**************************')
|
|
|
|
individual_orders_open_li = response_data
|
|
|
|
return individual_orders_open_li
|
|
# ### END ### API External Impexium Methods ### get_individual_orders_open() ###
|