What this workflow does
This workflow automatically finds and marks old shipment packages as “DELETE” in two MySQL databases. It solves the problem of spending many hours manually cleaning package records that are a month old or more and have the status “TRANSPORTE-RECEBIDO”. After cleaning, it alerts the team with messages on Telegram, so everyone knows the task is done.
Who should use this workflow
This workflow is useful for managers and teams who work with multiple MySQL databases storing shipment package records. It helps users who want to reduce time spent on manual cleanup and avoid mistakes during deletion. It works well for companies needing real-time notifications about maintenance status.
Tools and services used
- n8n workflow automation: Runs the full cleaning and notification process.
- MySQL databases (PPM and OBJ): Two databases storing shipment package data.
- Telegram Bot API: Sends notification messages to chat groups.
- Cron scheduler: Automates workflow daily at 8 AM.
- HTTP Webhook: Allows manual trigger from a URL.
How this workflow works
Inputs
The workflow starts from two triggers: a daily Cron at 8 AM and a manual HTTP Webhook call. Both trigger the package cleanup process.
Processing steps
- It runs two SQL queries, one on each MySQL database (PPM and OBJ).
- Each query finds package tokens where the module is “pacoteProduto”, the status is “TRANSPORTE-RECEBIDO”, and the date is older than 1 month.
- For all these package tokens, it updates the module value to “DELETE”.
- After each database update, the workflow sends a Telegram message confirming cleanup for PPM or OBJ.
Outputs
- Package records with old status get marked for deletion in both databases.
- Telegram messages are posted to the specified chat to notify about the cleanup events.
Beginner step-by-step: How to build this in n8n
Importing the workflow
- Use the Download button on this page to get the workflow file.
- In the n8n editor, click on “Import from File” and select the downloaded workflow.
Set up credentials and settings
- Add the MySQL credentials for the two databases, named PPM and OBJ.
- Set the Telegram Bot API credentials and enter the correct chat IDs for the notification nodes.
- Check the SQL queries in both MySQL nodes to confirm they match your database schema if needed.
Testing and activation
- Run the workflow once using “Execute Workflow” in n8n to test if packages get marked and Telegram messages arrive.
- If testing succeeds, activate the workflow toggle to enable automatic daily runs and webhook triggers.
Using self-host n8n is recommended for reliable operation in production.
Customizations
- Change the time frame in the SQL query’s DATE_SUB interval to adjust how old packages need to be for cleanup (example: from “1 MONTH” to “2 MONTHS”).
- Modify the Cron node’s scheduled hour to fit operational needs if 8 AM is not suitable.
- Add extra Telegram nodes if notifying multiple chat groups or channels is required.
- Alter SQL queries to archive or permanently delete records if company policies demand beyond marking with “DELETE”.
Common issues and fixes
- MySQL syntax errors: Check for correct SQL commands and compatibility with your database version.
- Telegram messages not delivered: Verify Telegram Bot API tokens and chat IDs for accuracy and expiration.
- Webhook 404 errors: Confirm the webhook URL is copied correctly and the workflow is activated before testing.
Summary of results
✓ Packages older than 1 month with status “TRANSPORTE-RECEBIDO” get flagged for deletion automatically.
✓ Team members receive instant Telegram notifications after cleanup.
→ Reduced manual workload and improved accuracy in database maintenance.
→ Scheduled and manual triggers offer flexible workflow control.
