FRESH PERSPECTIVE
Extending Cloud Capabilities with APIs: Some Shortcuts
Wish the cloud application you use had a specific report? Lacking the ability to schedule data exports? You’re not alone. But there are options. One great thing about cloud applications is that most have a public API, or Application Programming Interface, available. Using the public API, we can often gather the data we need for…

08/12/2021
Wish the cloud application you use had a specific report? Lacking the ability to schedule data exports? You’re not alone. But there are options. One great thing about cloud applications is that most have a public API, or Application Programming Interface, available.
Using the public API, we can often gather the data we need for our request. I prefer Python programming for much of my automation because of its ease-of-use, available open-source libraries, and flexibility. I recently noticed a client was manually creating a report from a cloud application, taking hours and hours every week to manually find each piece they needed in the UI to update their spreadsheet. Perfect for Python! I built a script that calls the API, organizes the data, writes it to a file (creates the report), and emails interested parties, calling out specific aspects of the report.
Process Flow:
1. Kick off the script. I was using a Linux environment with Python installed (Crontab for scheduling scripts!). A lot can happen from one week to the next, so a daily report made more sense and was requested.
2. Call the API. I prefer the “requests” library of Python for its simplicity to call various APIs. If the API supports it, filter the data. For example, if you only need 1 week of data, use parameters to only request the last week of data from the API. This helps with load and processing times.
3. Organize the data. The API I was using sent data in JSON format, so after pulling that data, I could remove any unnecessary data to work with a smaller dataset and even add my own data – percent changes from one day to the next or exceeded thresholds…more on that in a bit.
4. Write the file (/report). Python’s built-in “csv” library has a function for writing a dictionary (JSON) to a file! Quite convenient!
5. Send email. Python also has a built-in library for handling email! Now, nobody, especially high-level management, wants an email with all of the details and search for an important piece of data or two. That’s where that added data comes into play! Since I added percent changes from day to day and had a threshold set in the code (a config file makes it an easy place to change in case that threshold needs to change at some point), only those key warnings outside the threshold are called out in the email. I also attached a full report to the email to allow a deeper dive, if needed.
Enjoy!
By Jeremy Foszcz, Technical Manager
