Integration Scripts Generation — Guided Lab
Scenario:
You want to connect multiple systems—for example, a database, a web API, and a CSV report—to automate a workflow. Writing all the integration code manually is tedious. Your AI assistant can generate scripts that integrate these systems efficiently.
Step 0: Define Your Goal
Example workflow:
- Fetch customer data from a database
- Call an external API to enrich customer information (e.g., validate email)
- Save the results into a CSV report
Goal: Generate a Python script that performs all steps automatically.
Step 1: Craft the AI Prompt
Treat AI as a workflow automation developer. Include:
- Systems involved (database, API, CSV)
- Operations to perform (fetch, validate, save)
- Optional: error handling, logging, and libraries to use
Example Prompt:
Write a Python script that:
1. Reads customer data from a PostgreSQL database (columns: id, name, email)
2. Validates emails using an external API
3. Writes the validated results into a CSV file
Include error handling, logging, and comments explaining each step.
Step 2: AI Output Example
import psycopg2
import requests
import csv
# Connect to PostgreSQL
conn = psycopg2.connect(dbname="mydb", user="user", password="pass", host="localhost")
cur = conn.cursor()
cur.execute("SELECT id, name, email FROM customers")
customers = cur.fetchall()
validated_customers = []
for customer in customers:
id, name, email = customer
try:
response = requests.get(f"https://api.emailverify.com/verify?email={email}")
response.raise_for_status()
is_valid = response.json()['valid']
validated_customers.append((id, name, email, is_valid))
except requests.RequestException as e:
print(f"Error validating {email}: {e}")
# Write results to CSV
with open("validated_customers.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["ID", "Name", "Email", "Valid"])
writer.writerows(validated_customers)
cur.close()
conn.close()
print("Integration script completed successfully.")
Step 3: Test the Script
- Ensure your database credentials and API key are correct
- Run the script and verify the CSV output
- Check error handling and logging for robustness
Step 4: Mini Lab Challenges
- Modify the script to handle multiple APIs and merge results.
- Automate daily execution using cron or Task Scheduler.
- Include data transformations before writing to CSV (e.g., formatting names).
- Challenge: Integrate Excel reports instead of CSV using
openpyxl.
Step 5: Pro Tips
- Clearly specify systems, APIs, and output format in the prompt
- Ask AI to include error handling, logging, and comments
- Test incrementally: database fetch → API call → CSV output
- Use AI to adapt scripts to different environments or endpoints
- Iteratively refine prompts for efficiency and readability
Lab Summary
- AI can generate integration scripts connecting databases, APIs, and files
- Clear prompts + workflow description = automated, tested scripts
- AI helps reduce manual coding and integration errors
- Using AI for integration increases productivity and ensures repeatable workflows


