question

mrvitas avatar image
mrvitas asked David Marginian Deactivated edited

python script with 16 API tokens extracting daily total payments from 16 locations has suddenly stopped working

I have inherited a python script which runs daily, extracting total payments from 16 locations

and creating a csv file for import into our ERP GL application. The python script makes

16 API calls with same amount of tokens to extract this data. A week ago, the process stopped working.


The python log file shows an error: payment_response = payment_response['elements'] KeyError: 'elements'

When I start researching and going down that rabbit hole, the error messages keep changing until I get an error for one of the data points being null or empty.


This script has been running, non-stop for a few years. A small change was implemented a few weeks ago to add 3 API tokens and 3 locations. All was tested successfully and it has been running successfully.


For a person with very little python or API experience, what would you recommend be the next few steps for troubleshooting this puzzling issue?

REST API
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated edited

First of all, it sounds like this integration is a violation of our terms, as we do not allow the use of merchant tokens for integrations that will be used for multiple merchants.

The error seems pretty straightforward, the "elements" key isn't present on the payments response. I would start by printing out the response to see what it looks like. Are you checking the response to make sure it is successful (you are getting a 200) before processing the JSON? If not, you should be because you may be getting some type of error response in which case there would be no elements. I would suggest you check for a valid response and check for the presence of the "elements" tag before you try to use it in your script.

3 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mrvitas avatar image mrvitas commented ·

Thank you so much for your response. Forgive me for sounding ignorant, but I'm assuming we are one merchant with multiple locations. The API tokens were obtained from each location. I'll have to parse through your next recommended answer and how to print out the response before processing the JSON. (...all new to me). However, I'm still unclear how this has been running and working for a long time and suddenly stopped. This is not a new script.

0 Likes 0 ·
David Marginian avatar image David Marginian ♦♦ mrvitas commented ·

Ok, if you are the merchant then you are of course allowed to use merchant tokens to access your own data. From your question it wasn't clear to me if you were a 3rd party dev, or a merchant. If you redact all sensitve data from the script (tokens, etc.) you can post it here in a moderator's only post (See the Viewable by all users dropdown below the submit button) and I can take a quick look.

0 Likes 0 ·
David Marginian avatar image David Marginian ♦♦ David Marginian ♦♦ commented ·

That is not a very good script and isn't robust at all. What I suspected is correct, It blindly assumes the response was successful and that the elements key is there. Just FYI this is likely failing because 1. it is a script that assumes that all requests work, all the time and 2) Recent issues introduced in the cash_events endpoint - https://community.clover.com/questions/27756/why-am-i-getting-500-internal-server-error-intermi.html. I would strongly suggest you fix the script to 1) Check for a successful response 2) Not assume "elements" will be in the response.

Also, your usage here really does appear to be a violation of our terms, those merchants don't seem to be related to each other.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community