Skip to content

Instantly share code, notes, and snippets.

@micahwalter
Last active March 20, 2019 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahwalter/e4cb990a1691d33476e5f3995dbd3855 to your computer and use it in GitHub Desktop.
Save micahwalter/e4cb990a1691d33476e5f3995dbd3855 to your computer and use it in GitHub Desktop.
### code to make rest calls to the Tessitura API
import requests
import json
import base64
import os
## Tessitura API
hostName = os.environ['TESSITURA_API']
## The full credential string like "user:group:location:password"
credentials = os.environ['REST_CREDENTIALS']
def api_call(method, *args, **kwargs):
params = kwargs.get('params', None)
data = kwargs.get('data', None)
## call the rest API
rsp = api_rest_call(method, args[0], params=params, data=data)
return rsp
def api_rest_call(method, *args, **kwargs):
params = kwargs.get('params', None)
data = kwargs.get('data', None)
rest_endpoint = 'TessituraService/'
url = hostName + rest_endpoint + method
r = {}
headers = {
'Accept': "application/json",
'Content-Type': "application/json",
'Authorization': api_prepare_auth_string()
}
if args[0] == "GET":
r = requests.get(url, params=params, headers=headers)
elif args[0] == "POST":
r = requests.request("POST", url, data=str(data), headers=headers)
## return parsed response
j = r.json()
return j
def api_prepare_auth_string():
encoded = base64.b64encode(str.encode(credentials))
encoded = str(encoded.decode())
authHeader = 'Basic ' + encoded
return authHeader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment