1. Opening Problem Statement
Meet Brian, an Amazon advertising manager overwhelmed by daily performance reports from multiple campaigns. Every morning, Brian downloads CSV and Excel reports, manually combs through search term data, campaign budgets, and targeting metrics. This labor-intensive process easily takes 3-4 hours daily and is prone to occasional errors in analysis, leading to missed optimization opportunities and wasted ad spend. Brian needs a better way to harness his data quickly and consistently, ensuring immediate, actionable recommendations for optimizing his Amazon Ads campaigns.
This is exactly where the “Amazon Ads AI Optimization” workflow in n8n shines.
2. What This Automation Does
When this workflow runs, it automates the entire cycle from report collection to actionable insights, specifically for Amazon Sponsored Products campaigns. Here’s what it does:
- 1. Automatically scans a chosen Google Drive folder for freshly uploaded Amazon Ads reports in XLSX or CSV format.
- 2. Downloads each report file and extracts structured data relevant to campaigns, search terms, targeting, placements, and budgets.
- 3. Parses filenames to categorize reports into datasets such as search_terms, campaigns, targeting, placement, and budgets.
- 4. Merges and cleans these parsed datasets into a unified JSON structure tailored for AI consumption.
- 5. Sends the cleaned data as input to GPT-4o via n8n’s Langchain OpenAI node, which analyzes the data and generates specific campaign optimization recommendations—bid adjustments, budget scaling, and keyword and targeting suggestions.
- 6. Formats the AI’s JSON response into a human-readable, detailed HTML email summary.
- 7. Sends this personalized Amazon Ads optimization email automatically to the marketing team or campaign manager.
By automating this workflow, users save several hours daily, reduce manual error risk, and gain consistent, data-driven insights faster—empowering smarter bids and budget decisions that impact ad ROI positively.
3. Prerequisites ⚙️
- n8n account configured and ready to run workflows
- Google Drive account with OAuth2 access configured in n8n to read files
- OpenAI API account with access to GPT-4o model configured via Langchain node in n8n
- Gmail account authorized in n8n to send optimization summary emails
- Amazon Ads accounts configured to schedule and deliver Sponsored Product reports (Search Term, Campaign, Targeting, Placement, Budget) daily to Google Drive or email
Optionally, self-host your n8n on platforms like Hostinger for full control and reliability: https://buldrr.com/hostinger
4. Step-by-Step Guide to Setup Amazon Ads AI Optimization in n8n
Step 1: Prepare Your Amazon Ads Reports
In your Amazon Ads Console, schedule the following reports to run every day for the last 30 days, in XLSX or CSV format:
- Search Term Report (Detailed) → Sponsored_Products_Search_Term_Detailed_L30
- Targeting Report (Detailed) → Sponsored_Products_Targeting_Detailed_L30
- Campaign Report (Summary) → Sponsored_Products_Campaign_L30
- Placement Report (Summary) → Sponsored_Products_Placement_L30
- Budget Report (Summary) → Sponsored_Products_Budget_L30
Ensure filenames include these key words, so the workflow can identify them properly.
Step 2: Upload Reports to Google Drive Folder
Choose a dedicated Google Drive folder to hold all these report files. You can upload manually, set up Gmail automation to save attachments, or sync a local folder to Drive.
Note: The workflow’s List Files node must be configured to watch this folder for new files.
Step 3: Configure Google Drive Credentials in n8n
In n8n, add Google Drive OAuth2 credentials with read access to your reports folder.
Step 4: Set Email Details
Use the Email Options node to enter your recipient email address and email subject line.
You will later see this email setup used in the Gmail node.
Step 5: Set Up the Trigger
Initially, the workflow uses a manualTrigger node for testing. You can replace it with a scheduled trigger (e.g., Cron node) to run daily automatically.
Step 6: Configure the File Listing and Download
The List Files node scans the Drive folder and feeds all files one by one into the Get File node downloading each file as binary data.
Step 7: Identify File Types with “is XLSX” Node
The workflow uses an If node named is XLSX to check whether filenames contain .xlsx, to route files to the proper extractor.
Step 8: Extract Data from XLSX and CSV Files
Files detected as XLSX go to the Extract XLSX Data node; CSV files go to the Extract CSV Data node. Both parse the files into JSON for further processing.
Step 9: Preserve File Names
Each extracted file’s JSON data is tagged with filenames using Set nodes (Preserve File Name and Preserve CSV File Name) for routing downstream.
Step 10: Merge Data Streams
The Merge XLSX and CSV node consolidates data from both formats into one output stream for unified handling.
Step 11: Format Data Into Campaign Objects
A Code node named Format Data processes all incoming JSON objects. It maps filenames to categories like search_terms, campaigns, targeting, placement, and budgets. The code snippet carefully normalizes the name and throws errors if filename patterns don’t match. This step prepares neat structured input for AI analysis.
const result = {};
for (const item of items) {
const fileName = item.json.fileName || item.json.name || 'unknown_file';
const baseName = fileName
.split('.')[0]
.replace(/s+/g, '_')
.toLowerCase()
.replace(/s*(d+)$/, '')
.replace(/_+$/, '')
.trim();
const map = [
{ key: 'search_terms', regex: /search_term/ },
{ key: 'campaigns', regex: /campaign/ },
{ key: 'targeting', regex: /targeting/ },
{ key: 'placement', regex: /placement/ },
{ key: 'budgets', regex: /budget/ },
];
const entry = map.find(m => m.regex.test(baseName));
const mappedKey = entry ? entry.key : null;
if (!mappedKey) {
throw new Error(`${fileName} → ${baseName} → Unrecognized file name structure`);
}
result[mappedKey] = result[mappedKey] || [];
result[mappedKey].push(item.json);
}
return [{ json: result }];
Step 12: AI Analysis with GPT-4o
The prepared JSON object is sent to the AI Analyze node (Langchain’s chainLlm node) which uses GPT-4o with a specific system prompt. This prompt instructs the AI to analyze campaign data and return actionable recommendations like:
- Campaign bid multipliers and bid placement adjustments
- Budget increase/decrease actions for campaigns
- Exact match keyword additions and negative keyword lists
- Targeting recommendations (pause or increase bid on targets)
The AI returns a strict JSON format with these insights.
Step 13: Email Generated Optimizations
The workflow crafts a detailed HTML email summarizing all recommended campaign adjustments, keyword recommendations, and targeting tips in a user-friendly format. The Email Optimizations Gmail node sends this directly to the configured recipient.
5. Customizations ✏️
- Change Report Folder: In the
List FilesGoogle Drive node, update thefolderIdfilter to point to the Drive folder where your Amazon Ads reports are stored. This allows you to organize your reports in any folder without altering the workflow. - Email Recipients and Subject: Modify the
Email Optionsnode to customize who gets the optimization summary emails and subject lines, for better team collaboration or client reporting. - Switch AI Model: In the
OpenAI Chat Modelnode, change the model from “gpt-4o” to any available OpenAI model according to your subscription or preference (e.g., gpt-4, gpt-3.5-turbo). - Upgrade to Amazon Ads API: Replace the manual report gathering with an automated connection to Amazon Advertising’s API to programmatically generate and fetch reports directly, eliminating manual uploads.
- Customize AI Prompt: Refine the system prompt in the
AI Analyzenode to tailor recommendations to your business goals, like targeting specific ROAS thresholds or prioritizing certain campaign types.
6. Troubleshooting 🔧
Problem: Workflow fails to process files with error “Unrecognized file name structure”.
Cause: The uploaded report files do not match expected filename patterns.
Solution: Ensure filenames contain keywords like search_term, campaign, targeting, placement, or budget exactly as spelled. Rename files or adjust mapping regex in the Format Data node.
Problem: Emails are not sending.
Cause: Gmail OAuth2 credentials not authorized or setup incomplete.
Solution: Check and reauthorize Gmail OAuth2 credentials in n8n. Ensure the sending address matches authorized Gmail account. Test sending individual emails from the Gmail node.
Problem: AI response parsing fails in email template.
Cause: The AI model returned invalid JSON or unexpected format.
Solution: Examine the prompt in the AI Analyze node and confirm the AI outputs the strict required JSON. Test the AI node separately and validate JSON output before sending emails.
7. Pre-Production Checklist ✅
- Verify Google Drive folder contains the correctly named files before workflow runs.
- Test AI node separately with sample JSON input to validate response format.
- Send test emails using the Gmail node with your address to check formatting and delivery.
- Backup your n8n workflow and credential configurations before production deployment.
8. Deployment Guide
Activate your workflow by enabling it in n8n. Replace the manual trigger node with a Cron trigger or other schedule trigger node to run daily after reports are expected to be uploaded.
Monitor workflow executions in n8n logs. Set up error alerts via email or webhook for failures in file extraction or AI processing nodes.
9. FAQs
Q: Can I use email attachments directly instead of Google Drive?
A: Yes, but you need to add a Gmail trigger node and automatic uploader to Google Drive or adapt the workflow to parse attachments directly.
Q: Does this consume a lot of OpenAI API credits?
A: The AI model GPT-4o is a powerful model and may use moderate credits depending on data size; limit frequency accordingly.
Q: Is my data secure?
A: Data flows through your n8n environment and cloud services; ensure you comply with your organization’s privacy policies and secure credentials properly.
10. Conclusion
By following this comprehensive guide, you’ve built an end-to-end automated Amazon Ads optimization workflow using n8n and GPT-4o. This workflow frees you from time-consuming manual report analysis by automatically ingesting campaign data from Google Drive, classifying and formatting it, then leveraging powerful AI to generate specific bid, budget, and keyword recommendations—all delivered cleanly via email.
You save hours each week, reduce costly errors from manual processing, and gain precision in campaign adjustments. Next, consider automating Amazon Ads campaign creation or integrating with Google Sheets dashboards for real-time tracking.
Start improving your Amazon Ads performance with fewer headaches and more data-driven confidence.