I'm attempting to pull JSON data from an API and struggling to nail down the source of my problems. Currently I get accurate data if message = "" but so far any non-empty query parameters return a 403 error. The API documentation asks for parameters to be formatted as "customerCode=XXX" and I've been able to produce valid queries in the API Sandbox. I assume the problem is somewhere in the getSignature function, but I've rewritten it a few ways and .encode() or bytes() gives me the same result. If the code looks coherent and it's a syntax error on my end I can reach out to the support team. Again, when message is an empty string I get valid results back so I'm puzzled. Error occurs on all tested Report pages with multiple different query parameters tested per page. Relevant import functions are not pasted here but are included in the code.
#Current hash
def getSignature(message):
hashed = hmac.new(key, message.encode('utf-8') , hashlib.sha256)
return base64.b64encode(hashed.digest())
#Header per API specs
def getData(report, message):
headers = {
'Content-Type' : 'application/json',
'Accept' : 'application/json',
'api-auth-id' : api_id,
'api-auth-signature' : getSignature(message)
}
data = requests.get(url + report, headers=headers)
data = data.json()
return data