Howdy,
I am using Python to make API requests, but I am getting different errors each time for different things. For example, part of my code is getting a contact. So, I will run my program and then I will get a error from my Python saying that it has returned as None (errors out because I try to manipulate the JSON but will error because None is not JSON). So, I initially thought this was issue with my code, but 2 things: 1.) It should never be None. Making a call to the API will always either return the contact or a 404 error. 2.) Running the code multiple times does not get repeated results. So I will run it once and it will error out on one user, but then when I run it again it will return that contact just fine, but then error out on a different one (all of this without changing my code). So, this has led me to believe this is either an error with Syncro’s API, or maybe something with my headers? I am just not sure why I am not getting consistent results. I think that I have to be missing something here! Below is my Python code (the brackets are where I put in my information. Also, I know this function isn’t the prettiest, so my apologies!) :
def getApi(ending):
api_url = "https://{company_name}.syncromsp.com/api/v1/{0}".format(ending)
headers = {'Authorization' : '{apiKey}', 'accept': 'application/json'}
response = requests.get(api_url, headers=headers)
data = json.loads(response.text)
return data
Any help would be greatly appreciated.