Quick overview
This workflow watches a Google Drive folder for newly uploaded XLSX inventory reports, uses OpenAI (GPT-4.1 mini) to calculate per-product replenishment needs, writes the results back into the spreadsheet as new columns, and then updates and moves the processed file in Google Drive.
How it works
- Triggers when a new XLSX file is created in a specific Google Drive folder.
- Downloads the new file from Google Drive, extracts the XLSX rows, and splits the dataset into row batches.
- For each batch, builds a compact JSON prompt containing sales, purchase, and stock metrics per SKU and sends it to OpenAI GPT-4.1 mini to get a reorder quantity and a one-sentence Turkish reason per row.
- Maps the OpenAI results back onto the original rows by adding columns AB (need) and AC (reason), then continues until all batches are processed.
- Reassembles all rows in the original order, converts the result back to XLSX, and updates the original Google Drive file content.
- Moves the updated spreadsheet to a designated output folder in Google Drive.
Setup
- Add a Google Drive OAuth2 credential in n8n and select it in the Google Drive Trigger, Download, Update, and Move operations.
- Set the input folder to watch in the Google Drive trigger and set the destination folder in the Google Drive move step.
- Add an OpenAI API credential and select it in the OpenAI “Message a model” step (model: gpt-4.1-mini).
- Ensure your XLSX column headers match the fields referenced in the prompt-building code (for example KOD, Son 45/90/180 Satis Miktar, Son 45/90/180 Giris Miktar, DEPO, MKL, and store stock columns like SRN, BZK, HTY, etc.).
- Replace the placeholder brand name (MARKA ADI) in the OpenAI system prompt with your own brand name.