How to automate your CRM report with AI and Python
I'm currently experimenting with Anthropic AI potentials, and I'm increasingly impressed by what I'm finding.
In this article i will explore how to write a simple Python script to automate a report from my CRM.
Premise: I use Anaconda and its Jupyter notebook to write Python code, It's very convenient and free.
This is my first prompt to Claude Sonnet.
Hello, I'm a marketer with basic programming knowledge. I'd like to automate generating reports by pulling data from my Zoho CRM, similar to how Zapier's Zaps work. Ideally, I'd like to receive these reports via email every Monday morning.
Could you help me build an API or script to automate this process? What tools or libraries would be recommended to achieve this? Additionally, what would be required to run this API independently (without manual intervention)?
A step-by-step explanation would be greatly appreciated. Please let me know if you need any further information from me.
I wrote some context, then the request and at the end how to articulate the explanation.
The AI wrote me back with a chunk of code that will form the core structure of my script.
Then it asked me:
To proceed, I would need to know:
What specific data do you want to include in the reports?
Do you already have access to the necessary APIs?
What development and execution environment do you prefer to use?
Do you have experience with Python or would you prefer a different solution?
In this case, I have access to my CRM API and I want to include our contacts divided by nations and industries.
This script performs the following tasks:
Fetches data from Zoho CRM, counting contacts by country and profession.
Generates a report combining this data.
Sends the report via email.
To use this script, you will need to:
Install the required dependencies:
pip install -r requirements.txt
Replace the placeholders with your real data:
ZOHO_ACCESS_TOKEN: Your Zoho CRM access token
EMAIL_CREDENTIALS: The email credentials for sending the report
Configure automatic execution:
a. Open Task Scheduler on Windows
b. Create a new task
c. Set the trigger for every Monday morning
d. In the action, specify the path to the Python interpreter and the script.
It might seem straightforward, but it can get tricky. If you encounter any difficulties with specific steps, you can always ask the AI for help.
Ok, now I need to figure out how to get my Zoho Access Token.
AI wrote for me this simple script.
I started by inserting my Zoho data and access token into the script. With the help of the AI, I was then able to implement all my desired functionalities:
Exporting more than 10 fields of data.
Specifying a date range to filter the contact data.
Generating a report with HTML tables and charts displaying time series.
Converting the report to a PDF attachment for email delivery due to Gmail compatibility issues.
And that's how it works! Now I have a complete report with everything.
Would you like to connect?
You can visit my website or add me on LinkedIn where I sometimes share short new content about my experiences and what I'm passionate about.