Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 48 additions & 25 deletions R1_example3.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 26 14:28:24 2024

@author: marcelomolinari
"""
R1 API Integration Script

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 28 14:20:26 2023.
This script demonstrates the usage of the R1 API for retrieving
JWT tokens, MSP-EC tenant IDs, and venue information.

@author: Marcelo M. Molinari
Created on Fri Jan 26 14:28:24 2024
@author: marcelomolinari
"""

import warnings
from R1_API import R1_API_calls
warnings.filterwarnings("ignore", message="Unverified HTTPS request")

HOST = 'base your for your region'
TENANT_ID = 'your tenant id'
CLIENT_ID = 'your client id'
SECRET_ID = 'your secret id'

r1 = R1_API_calls()
jwt = r1.getJWT(HOST, TENANT_ID, CLIENT_ID, SECRET_ID)['access_token']
print('jwt:', jwt)

mspEcTenantId = r1.getMspECs(HOST, TENANT_ID, jwt)[0]['tenant_id']
print('MSP-EC tenantId:', mspEcTenantId)

mspEcVenues = r1.getVenues(HOST, mspEcTenantId, jwt)
print('MSP-EC venues:', mspEcVenues)

# Suppress unverified HTTPS request warnings
warnings.filterwarnings("ignore", message="Unverified HTTPS request")

# Configuration
CONFIG = {
'HOST': 'base your for your region',
'TENANT_ID': 'your tenant id',
'CLIENT_ID': 'your client id',
'SECRET_ID': 'your secret id'
}

def main():
"""Main function to execute the R1 API calls."""
r1 = R1_API_calls()

# Get JWT token
jwt = get_jwt(r1)
print('JWT:', jwt)

# Get MSP-EC tenant ID
msp_ec_tenant_id = get_msp_ec_tenant_id(r1, jwt)
print('MSP-EC tenant ID:', msp_ec_tenant_id)

# Get MSP-EC venues
msp_ec_venues = get_msp_ec_venues(r1, msp_ec_tenant_id, jwt)
print('MSP-EC venues:', msp_ec_venues)

def get_jwt(r1):
"""Retrieve JWT token."""
response = r1.getJWT(CONFIG['HOST'], CONFIG['TENANT_ID'],
CONFIG['CLIENT_ID'], CONFIG['SECRET_ID'])
return response['access_token']

def get_msp_ec_tenant_id(r1, jwt):
"""Retrieve MSP-EC tenant ID."""
response = r1.getMspECs(CONFIG['HOST'], CONFIG['TENANT_ID'], jwt)
return response[0]['tenant_id']

def get_msp_ec_venues(r1, msp_ec_tenant_id, jwt):
"""Retrieve MSP-EC venues."""
return r1.getVenues(CONFIG['HOST'], msp_ec_tenant_id, jwt)

if __name__ == "__main__":
main()