N8n Workflow JSON Examples: Your Guide To Automation
Hey guys! Ever felt like you're drowning in repetitive tasks? Well, you're not alone! In today's fast-paced digital world, automation is the name of the game. And when it comes to workflow automation, n8n is a seriously powerful tool. But let's be real, diving into a new platform can feel a bit overwhelming, especially when you're faced with lines of code and JSON structures. That's why we're here to break it all down for you with some practical n8n workflow JSON examples. Get ready to unlock the full potential of n8n and streamline your processes like a pro!
Understanding n8n Workflows and JSON
Before we jump into the examples, let's quickly cover the basics. n8n is a no-code/low-code platform that allows you to automate tasks and workflows by connecting different apps and services. Think of it as a digital domino effect – one action triggers another, and so on, until your entire process is automated. Now, where does JSON come into play? JSON (JavaScript Object Notation) is a lightweight data-interchange format that's easy for humans to read and write, and easy for machines to parse and generate. In n8n, workflows are often represented and stored as JSON objects. This means that you can define the structure, nodes, and connections of your workflow using JSON. Understanding this structure is key to creating and modifying workflows effectively. So, in essence, JSON acts as the blueprint for your automation masterpiece within n8n. It dictates how data flows, how different nodes interact, and the overall logic of your workflow. Mastering JSON in n8n empowers you to build intricate automations, troubleshoot issues with precision, and share workflows seamlessly with your team. It’s like learning the language of automation, opening doors to a world of efficiency and productivity. Forget about those tedious manual tasks – with n8n and a bit of JSON knowledge, you’ll be automating like a boss in no time!
Basic n8n Workflow JSON Example
Let's start with something simple. This example demonstrates a basic workflow that triggers when a new lead is added to a Google Sheet and sends a welcome email via Gmail. This n8n workflow JSON example represents a foundational automation, ideal for understanding the core structure of an n8n workflow definition. It includes nodes for triggering the workflow (in this case, when a new row is added to a Google Sheet), processing the data (extracting the lead's email address), and performing an action (sending an email through Gmail). By examining this example, you can learn how to define nodes, specify their types and configurations, and connect them together to create a functional workflow. This is the perfect starting point for building more complex automations. Understanding this example will help you grasp the fundamental concepts of workflow design in n8n, such as event triggers, data manipulation, and external API integrations. Remember, every great automation starts with a simple idea, and this n8n workflow JSON example is the perfect foundation upon which to build your automation empire.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [240, 160]
},
{
"parameters": {
"spreadsheetId": "YOUR_SPREADSHEET_ID",
"range": "Sheet1!A:B",
"options": {}
},
"name": "Google Sheet",
"type": "n8n-nodes-base.googleSheet",
"typeVersion": 1,
"position": [480, 160],
"credentials": {
"googleSheetsOAuth2Api": "YOUR_GOOGLE_SHEETS_CREDENTIALS"
}
},
{
"parameters": {
"fromEmail": "YOUR_GMAIL_ADDRESS",
"toEmail": "={{$node[\"Google Sheet\"].data[\"values\"][0][1]}}",
"subject": "Welcome!",
"text": "Hey there! Welcome to our platform!"
},
"name": "Gmail",
"type": "n8n-nodes-base.gmail",
"typeVersion": 1,
"position": [720, 160],
"credentials": {
"gmailOAuth2Api": "YOUR_GMAIL_CREDENTIALS"
}
}
],
"connections": {
"Start": {
"main": [[{"node": "Google Sheet", "type": "main", "index": 0}]]
},
"Google Sheet": {
"main": [[{"node": "Gmail", "type": "main", "index": 0}]]
}
}
}
Explanation:
- nodes: This array defines the individual steps in the workflow.
- Start: The starting point of the workflow.
- Google Sheet: This node retrieves data from a Google Sheet. You'll need to replace
YOUR_SPREADSHEET_IDwith your actual spreadsheet ID and configure your Google Sheets credentials. - Gmail: This node sends an email via Gmail. Replace
YOUR_GMAIL_ADDRESSwith your Gmail address and configure your Gmail credentials. ThetoEmailparameter dynamically retrieves the email address from the Google Sheet data. - connections: This object defines how the nodes are connected. In this case, the
Startnode is connected to theGoogle Sheetnode, and theGoogle Sheetnode is connected to theGmailnode.
Intermediate n8n Workflow JSON Example
Now, let's level up a bit. This example demonstrates a workflow that listens for new tweets containing a specific hashtag, saves the tweet data to a database, and sends a notification to a Slack channel. This is where things start to get interesting. This intermediate n8n workflow JSON example showcases the power of n8n in handling real-time data and integrating with multiple services. It includes nodes for listening to a Twitter stream, filtering tweets based on a specific hashtag, storing tweet data in a database (like PostgreSQL or MySQL), and sending notifications to a Slack channel. This example demonstrates how to use conditional logic (e.g., only process tweets with a specific hashtag) and data transformation (e.g., extracting relevant information from the tweet object). By studying this example, you can learn how to build more sophisticated automations that react to events in real-time and perform complex data processing tasks. This is the perfect example for those looking to automate social media monitoring, data analysis, or any other task that involves real-time data streams and multiple integrations. Understanding this example will significantly expand your capabilities in n8n and allow you to tackle more challenging automation projects. So, get ready to dive in and unleash the power of real-time automation!
{
"nodes": [
{
"parameters": {
"search": "#n8n",
"options": {}
},
"name": "Twitter Trigger",
"type": "n8n-nodes-base.twitterTrigger",
"typeVersion": 1,
"position": [240, 160],
"credentials": {
"twitterOAuth2Api": "YOUR_TWITTER_CREDENTIALS"
}
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json.text}}",
"operation": "contains",
"value2": "#n8n"
}
]
}
},
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [480, 160]
},
{
"parameters": {
"host": "YOUR_DATABASE_HOST",
"port": 5432,
"database": "YOUR_DATABASE_NAME",
"table": "tweets",
"user": "YOUR_DATABASE_USER",
"password": "YOUR_DATABASE_PASSWORD",
"columns": [
{
"name": "tweet_id",
"value": "={{$json.id_str}}"
},
{
"name": "text",
"value": "={{$json.text}}"
},
{
"name": "created_at",
"value": "={{$json.created_at}}"
}
]
},
"name": "PostgreSQL",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [720, 160]
},
{
"parameters": {
"url": "YOUR_SLACK_WEBHOOK_URL",
"text": "New tweet with #n8n: {{$json.text}}"
},
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 1,
"position": [960, 160]
}
],
"connections": {
"Twitter Trigger": {
"main": [[{"node": "IF", "type": "main", "index": 0}]]
},
"IF": {
"main": [[{"node": "PostgreSQL", "type": "main", "index": 0}]],
"false": []
},
"PostgreSQL": {
"main": [[{"node": "Slack", "type": "main", "index": 0}]]
}
}
}
Explanation:
- Twitter Trigger: This node listens for new tweets matching the search query
#n8n. You'll need to configure your Twitter credentials. - IF: This node checks if the tweet text contains the hashtag
#n8n. This allows you to filter the tweets and only process those that are relevant. - PostgreSQL: This node saves the tweet data to a PostgreSQL database. You'll need to replace the placeholder values with your database credentials and ensure that the
tweetstable exists with the specified columns. - Slack: This node sends a notification to a Slack channel. Replace
YOUR_SLACK_WEBHOOK_URLwith your Slack webhook URL. - connections: The
Twitter Triggernode is connected to theIFnode, which filters the tweets. ThePostgreSQLnode is connected to theIFnode'strueoutput, meaning that only tweets containing#n8nwill be saved to the database. Finally, thePostgreSQLnode is connected to theSlacknode, which sends a notification about the new tweet.
Advanced n8n Workflow JSON Example
Alright, let's get serious! This example demonstrates a workflow that receives data from a webhook, transforms it using JavaScript code, calls an external API, and updates a CRM system. This advanced n8n workflow JSON example demonstrates the true power and flexibility of n8n. It includes nodes for receiving data from a webhook, transforming the data using a Function node with custom JavaScript code, calling an external API (like a weather API or a payment gateway), and updating a CRM system (like Salesforce or HubSpot). This example showcases how to handle complex data transformations, integrate with various APIs, and build sophisticated workflows that automate critical business processes. By studying this example, you can learn how to leverage the full potential of n8n to create custom solutions tailored to your specific needs. This is the perfect example for those looking to build complex integrations, automate data processing pipelines, or create custom applications using n8n. Understanding this example will empower you to tackle the most challenging automation projects and unlock the full potential of n8n as a powerful automation platform. So, buckle up and get ready to explore the world of advanced automation!
{
"nodes": [
{
"parameters": {
"path": "/webhook",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [240, 160]
},
{
"parameters": {
"jsCode": "// Transform the data received from the webhook\nlet data = $json.body;\n\n// Add a new field\ndata.processed = true;\n\nreturn data;"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [480, 160]
},
{
"parameters": {
"requestMethod": "GET",
"url": "https://api.example.com/data?id={{$json.id}}",
"options": {}
},
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [720, 160]
},
{
"parameters": {
"operation": "update",
"objectType": "contact",
"properties": [
{
"name": "last_contacted",
"value": "={{NOW}}"
}
],
"options": {}
},
"name": "HubSpot",
"type": "n8n-nodes-base.hubspot",
"typeVersion": 1,
"position": [960, 160],
"credentials": {
"hubspotApi": "YOUR_HUBSPOT_CREDENTIALS"
}
}
],
"connections": {
"Webhook": {
"main": [[{"node": "Function", "type": "main", "index": 0}]]
},
"Function": {
"main": [[{"node": "HTTP Request", "type": "main", "index": 0}]]
},
"HTTP Request": {
"main": [[{"node": "HubSpot", "type": "main", "index": 0}]]
}
}
}
Explanation:
- Webhook: This node receives data from a webhook. You'll need to define the path for the webhook.
- Function: This node executes JavaScript code to transform the data. In this example, it adds a new field called
processedto the data. - HTTP Request: This node makes an HTTP request to an external API. In this example, it retrieves data from
https://api.example.com/data?id={{$json.id}}. You'll need to replace this with your actual API endpoint. - HubSpot: This node updates a contact in HubSpot. You'll need to configure your HubSpot credentials and specify the properties to update.
- connections: The
Webhooknode is connected to theFunctionnode, which transforms the data. TheFunctionnode is connected to theHTTP Requestnode, which calls an external API. Finally, theHTTP Requestnode is connected to theHubSpotnode, which updates the CRM system.
Tips for Working with n8n Workflow JSON
- Use a JSON validator: Before importing a workflow JSON into n8n, validate it using a JSON validator to ensure that it's properly formatted.
- Start small: Begin with simple workflows and gradually increase complexity as you gain experience.
- Test frequently: Test your workflows thoroughly to ensure that they're working as expected.
- Use comments: Add comments to your JSON to explain the purpose of each node and connection. While JSON itself doesn't natively support comments, you can use a
descriptionfield within each node'sparametersto add explanatory text. - Version control: Use a version control system like Git to track changes to your workflow JSON files. This will allow you to easily revert to previous versions if something goes wrong.
- Leverage the n8n community: The n8n community is a great resource for getting help and sharing workflows. Don't hesitate to ask questions and contribute your own workflows to the community.
Conclusion
So there you have it – a comprehensive guide to n8n workflow JSON examples! By understanding the structure and syntax of n8n workflow JSON, you can unlock the full potential of this powerful automation platform. Whether you're a beginner or an experienced developer, these examples will provide you with a solid foundation for building your own custom automations. So go forth, experiment, and automate everything! Happy automating, folks!