2024-07-27 01:18:00 +00:00
import requests
2024-07-27 05:15:53 +00:00
from dotenv import load_dotenv
import os
2024-07-27 20:33:49 +00:00
pageSize = 10 # Just so I don't have to keep changing stuff
2024-07-27 20:38:06 +00:00
paramFields = ' id,companyName,name,lastInvoiceAmount,nextInvoiceAmount,agreementStatus ' # if we neeeed to make multiple similar calls we may as well save some typing
2024-07-27 20:33:49 +00:00
2024-07-27 20:38:06 +00:00
load_dotenv ( ) # make sure to include this avoid troubleshooting why your auth doesn't work for 40 minutes
2024-07-27 01:18:00 +00:00
def apiGetRequest ( api_base , endpoint , params , headers ) :
url = api_base + endpoint
resp = requests . get ( url , params = params , headers = headers )
if resp . status_code == 200 :
return resp . json ( )
2024-07-27 14:17:14 +00:00
else :
resp . raise_for_status ( )
2024-07-27 01:18:00 +00:00
2024-07-27 05:17:37 +00:00
api_base = os . environ [ " API_BASE " ]
2024-07-27 05:15:53 +00:00
authToken = os . environ [ " AUTH_TOKEN " ]
clientId = os . environ [ " CLIENT_ID " ]
2024-07-27 01:18:00 +00:00
endpoint = ' /finance/agreementrecap ' #endpoint for GET
2024-07-27 05:15:53 +00:00
headers = { ' Authorization ' : authToken , ' clientId ' : clientId } # DO NOT fill this out and then commit it to the publicly-viewable git repository, please
2024-07-27 20:38:06 +00:00
params = { ' pageSize ' : pageSize , ' conditions ' : ' agreementStatus= " ACTIVE " ' , ' fields ' : paramFields } # API call params--prepare to cry if your url encoding is sub-par
2024-07-27 05:15:53 +00:00
2024-07-27 05:17:37 +00:00
data = apiGetRequest ( api_base , endpoint , params , headers ) #Put it all together and whadya get
2024-07-27 05:15:53 +00:00
2024-07-27 01:18:00 +00:00
for item in data : #This is just iterating through whatever comes back and barfing the data in a readable way
2024-07-27 06:47:06 +00:00
print ( f " { item [ ' companyName ' ] } - { item [ ' name ' ] } - { item [ ' agreementStatus ' ] } " )
additionsEndpoint = ' /finance/agreements/ ' + str ( item [ ' id ' ] ) + ' /additions '
2024-07-27 20:33:49 +00:00
additions = apiGetRequest ( api_base , additionsEndpoint , { ' pagesize ' : pageSize } , headers )
2024-07-27 14:17:14 +00:00
for thing in additions : # Yo dawg I heard you like loops
2024-07-27 20:33:49 +00:00
print ( ' ' + thing [ ' product ' ] [ ' identifier ' ] + ' - $ ' + str ( thing [ ' unitPrice ' ] ) )
2024-07-27 20:38:06 +00:00
###################################################################################
2024-07-27 20:33:49 +00:00
####################### !!! DO NOT DISAPPOINT THE FROG WIZARD !!! #########################
# .-----.
# /7 . (
# / .-. \
# / / \ \
# / ` ) ( )
# / ` ) ). \
# .' _. \_/ . |
# .--. .' _.' )`. |
# ( `---...._.' `---.'_) .. \
# \ `----....___ `. \ |
# `. _ ----- _ `._ )/ |
# `. /" \ /" \`. `._ |
# `. ((O)` ) ((O)` ) `. `._\
# `-- '`---' `---' ) `. `-.
# / ` \ `-.
# .' `. `.
# / ` ` `. `-.
# .--. \ ===._____.======. ` ` `. .___.--` .''''.
# ' .` `-. `. )`. ` ` ` \ .' . ' 8)
# (8 . ` `-.`. ( . ` ` .`\ .' ' ' /
# \ `. ` `-. ) ` . ` ` \ .' ' . ' /
# \ ` `. ` . \`. .--. | ` ) ` .``/ ' // . /
# `. ``. . \ \ .-- `. ( ` /_ ` . / ' . '/ .'
# `. ` \ ` \ \ '-. `-' .' `-. ` . .'/ .'
# \ `.`. ` \ \ ) /`._.` `. ` . .' /
# | `.`. . \ \ (.' `. .' .'
# __/ .. \ \ ` ) \ \.' .. \__
# .-._.-' '" ) .-' `. ( '" `-._.--.
#(_________.-====' / .' /\_)`--..__________..-- `====-. _________)
#####################################################################################