How to Build Your Very First Workflow in n8n | n8n Tutorial β
n8nAgingπ
2024-09-05
Build Process β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BUILD CHATBOT WORKFLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β PLANNING β
β ββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Define βββββΊβ Choose βββββΊβ Setup β β
β β Scope β β Stack β β Project β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β DEVELOPMENT β
β βββββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Build βββββΊβ Add AI βββββΊβ Test & β β
β β Features β β Logic β β Debug β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β DEPLOYMENT β
β ββββββββββ β
β βββββββββββββββ βββββββββββββββ β
β β Deploy βββββΊβ Chatbot β βββ LIVE! β
β β to Cloud β β Running β β
β βββββββββββββββ βββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββKey Components β
- Project architecture
- Core features implementation
- Best practices
Transcript β
[00:00] In the previous videos, we had a look at setting up N8N on our local machines and in the cloud. So now it's time to create our very first workflow. From the N8N dashboard, let's click on start from scratch. The first thing I like to do is to rename my workflow. So go to the top left and let's click on the name of the workflow and let's call this something like pizza orders or whatever you want to call it. Next to the name of the workflow, we can add tags. By adding tags, we can actually filter
[00:32] on different workflows based on these tags. These are optional, but they can be extremely useful if you have a lot of workflows. So let's remove this folder and let's open up our workflow again. At the top here, we can switch between the editor and executions. We can use the executions tab to view pause executions of this workflow. In the top right, we have this toggle to activate our workflow and we'll only enable that once the workflow is production ready.
[01:02] We can also share the workflow with other team members if you are using the enterprise plan. And next to this, we also have a button to save the workflow. Now what I like to do after renaming my workflow is to click on these three buttons and then settings. Within settings, let's change the time zone to your local time zone. So I'll set mine to Johannesburg. Let's save the settings. And now let's have a look at the canvas. In the middle of the canvas, we have this button to add new nodes.
[01:33] And in the top right, we can click on this button to bring up all the available nodes where we can search for nodes or draw into a specific menu to view all the available nodes. The bottom left, we can click these buttons to zoom in and out of the canvas, or we can click on this button to center all the nodes in the middle of the view. We can also mouse drag on the canvas to select the nodes or hold control and left click to move around the canvas. This also works when holding in the
[02:04] middle mouse button. Now let's have a look at adding our first nodes to the canvas. When we click on this button, we will be prompted to add a trigger to our workflow. All workflows need at least one trigger. We can add a manual trigger, which can be used to test the workflow by clicking this test workflow button. Also, if we hover our mouse over the node, we get additional options. We can play the specific node by itself by clicking on display button. We can also deactivate a
[02:36] node and delete the node. There are also additional settings that can be accessed by clicking these three dots. Now let's continue looking at other events. We can also add on app events, and these are integrations with third party platforms. And scrolling through this list, you will notice that there are hundreds of integrations with third party providers. So we can use these nodes to watch for events in external systems and then trigger our workflow. A very common use case is
[03:07] when we receive an email, then do something with that email. We can also add on schedule as a trigger. And this is why I like to set my time zone up for my workflows. So this way I know exactly what time this trigger will run. We can use this schedule trigger node to start our workflow at specific intervals. For instance, we can set the interval to seconds, minutes, hours, days, weeks, months, or even custom. We can also tell it to run every day, every second day, third day, et cetera.
[03:39] Or we can also set the hour and minute that it should run. We can also set up webhook calls, and these are API endpoints that we can call from outside of N8N to trigger these workflows. We can also create forms, which we will do in this video actually. So I'm going to skip this node for now. We can also trigger a workflow from another workflow. And we can also add this on chat message node, which we can use to create AI chatbots. When adding this node to the canvas,
[04:10] you will notice this chat bubble appear. And when we click that, we will see this chat window. So if I type something like hello, obviously nothing will happen, as we haven't designed an AI model yet, but we will have a look at that in the series as well. And we also have specialized triggers, and we will have a look at some of these later on in the series, especially the error trigger, which will be triggered if our workflow fails. Now let's create our very first workflow. For this example, we'll create an order form for a restaurant.
[04:41] And once the user submits their order, we will do something with that data. So let's start by adding a new trigger, and let's add the on form submission trigger. Now in this view, we can see the URL that we can use to access the form. We can view a test URL, as well as a production URL. We will get back to these in a minute. We can also decide to add authentication to this form if we wanted to password protect this form itself. I'll simply leave this as none. Let's change the form path
[05:12] to something like orders. And you will also notice the path changing in this URL to something that's a bit more readable. Let's give our form a name, like pizza orders, and let's also give a description, like place your pizza orders here. And let's add a few fields to this form. Let's provide a field for the client to enter their name. So for the label, I'll enter your name. For the field type, I'll select text. And for the placeholder, let's enter your name here.
[05:43] Let's also make this a required field so the user needs to enter this field. Let's add another form field. For this one, let's call for the label, I'll enter pizza. Let's change the type to drop down list. And let's add a few pizza options. Let's add a margarita. Let's add another option. Let's make this one pepperoni. Let's add another option. We'll make this one Hawaiian. And let's make this one veggie. I'll leave multiple choice disabled, but let's enable required field.
[06:14] And let's add one more field for the size. So for the label, let's call it size. Let's change the type to drop down list. Let's add an option for medium. And let's add another option for large. Let's also make this required. Great, now that we have our form, we can test it out in a few ways. We can click on test step over here or on the left. Or if we went back to the canvas, we can click test step over here, or we can simply run the start button at the top of this node. I'm actually going to
[06:44] double click this node and run the test step over here. This will bring up our pizza order form with all the fields that we specified. So let's enter my name. Let's choose margarita. And for the size, I'll go for medium. And also submit the form. Great, this is telling us that the form was submitted. And if I go back to N8N, we can see this output on the right hand side of the screen. Next to the output title, we can see this green tick, which gives us some interesting info.
[07:15] It shows us the start time of this execution as well as the execution time. And we can also change the view from table JSON or schema. Now for the developers watching this, you will notice that in the JSON schema, the results is actually an array represented by these square brackets. And that's important to note as all N8N modules produce an array of values as output. We can also change the values that we received while clicking on this edit button.
[07:47] And from here, I can change the value and save this. This can be helpful for testing and troubleshooting your workflows. Another useful feature is the pin feature, which will pin this sample data to your node. This simply means that if we had to execute this flow, the exact same data will be maintained. If we unpin this and go back to the workflow and run this again, a new form will be displayed. So if you wanted to persist the data for troubleshooting and testing purposes,
[08:18] then pinning the data could be extremely useful. So in order to get some data into this flow, I'm going to run the form again. So I'll enter my name, let's select a pizza, and a size of medium. And let's submit this. Up until now, we've been using the test URL in order to test this application. But once you're ready to share this form with the world, you do want to click on the production URL and then pass that on. So if I copy this and open it in the browser, you will receive this message saying that
[08:50] the form does not exist. So for the production URLs, it's very important to activate your workflow by clicking on this toggle. And now that the workflow is active, we can refresh that page and now we can see that form. And we no longer get that development warning message at the top of this form either. And any data entered into this form will be passed to your workflow. Another important feature about these nodes is when we double click on a node, we can go to its settings and all nodes in N8N
[09:22] will have this settings tab. In here, you can provide nodes, which can be extremely valuable to remind yourself what a node was about or for your team members to see what the intent behind this node was. Let's enter something like pizza order form. We can also enable this toggle to display this node on the actual workflow. So if we go back to the canvas, we can see my node showing up over here. We can also rename a node by clicking on these three dots and let's click on rename.
[09:53] Let's call this receive order and let's rename this. Great, now let's move on to the second step of this pizza order form. And that takes us to actions. Actions allow us to interact with external applications like sending an email, posting on social media, adding data to a database, et cetera. And N8N offers integration with a lot of third party systems. So what we want to do is when we receive an order from our form, we want to store these values
[10:24] that we received in Airtable. Of course, you can use Google Sheets or a database or whatever you want. To add an action to this flow, we can simply click on this add button over here and we can see all the available actions that are available by expanding this action in app menu. And here you will find hundreds of integrations with external systems. Let's add Airtable and within Airtable, we can see different actions like creating a new record. Let's select that.
[10:54] This will immediately bring up the Airtable node, which we just added. In the center of the screen, we can see the node that's currently active, which is the Airtable node. We can move the center frame around by clicking on this tab over here and dragging it left or right to make a bit more space for our data. We can also rename the node from over here by clicking on this pencil. And of course we get different tabs for the parameters, the settings, and super useful is a link to the documentation
[11:26] for this specific node. In the left-hand side of the screen, we can see the output of other nodes within this workflow. For instance, the format we added earlier, and we can also see the data returned by that form. And of course on the right-hand side of the screen, we will see the output of this Airtable node. Another useful feature is on the left-hand side, we can quickly navigate to the previous node by clicking on this button. And now we have the order form active, or we can jump back to the Airtable node
[11:57] on the right-hand side over here. Cool. Now let's set up our connection with Airtable. For this, we do have to set up credentials to authenticate N8N on Airtable. So within this dropdown, let's click on create new credential. And at first, this might seem a little bit technical, but it's really not that bad. But if you do get stuck, then I highly recommend having a look at the documentation. We will get back to the screen in a minute. But first go over to Airtable.com and sign in or sign up for an account.
[12:29] Then from workspaces, click on create a workspace. And let's give this a name like pizza place. And within this workspace, let's click on create. And let's click on start from scratch. Now let's give our base a different name. So I'll just call mine pizza place again, and it's also renamed the table to something like orders. And I'm going to create a new column called pizza. I'll select single line of text, create field, and I'll create
[12:59] another column for the size, which is also a single line text. And that should be everything we need for now. I'm also going to select and delete these empty rows. Now that we have our table defined, all we need is this access token. So how do we get that? From Airtable, simply go to your name under account and click on builder hub. Then go to personal access tokens and click on create new token. I'll call my token, n8n pizza place.
[13:31] Then let's also add scopes. So under add scopes, we need to decide which scopes to add. And thankfully, n8n tells us exactly which scopes it needs. Data records read, data records write, and schema basis read. So back in Airtable, let's select data records read. Let's add data records write, and let's add schema basis read. And lastly, let's also add our base. And we only have one and that's pizza place.
[14:01] That's all we have to do. Let's click on create token. Let's copy this token back in n8n. Let's paste in that access token. And let's click on save. If everything was set up successfully, we should get this green tick. Great. So back in the Airtable node, our resource is record, our operation should be create. And from bases, let's select the pizza place base. And for the table, let's select the orders table. n8n will now automatically pull in the columns
[14:32] which we defined in our table. So name, pizza, and size, which corresponds to the columns in our table. Now we simply have to add the values of these fields, and we want to grab the values from the form. So thankfully, n8n is providing a schema on the left which shows exactly the fields that were retrieved from the form. So all we have to do to create this mapping is to grab this value from the form and drag it into the name input over here.
[15:02] Let's do the same for the pizza, and let's do the same for the size. I don't know about you, but n8n makes this mapping exercise extremely simple. So let's go ahead and test this out by clicking on test step. And on the right hand side, we can see the record that was inserted into the table. And if we go back to Airtable, we can see our value every year. Fantastic. So in order not to bore you, I decided just to edit out the part of me storing a whole bunch of records, and in the table,
[15:32] we now have several orders for different pizzas and pizza sizes. So now that our order form is complete, let's continue learning about n8n. I'm going to go back to the dashboard and create a new workflow for processing our orders. Let's call this process orders. For the trigger, I'm actually going to add the manual trigger for this process. When we run this workflow, I want to grab all the entries in our order form. So let's add a new node, and let's search for Airtable.
[16:04] And within Airtable, let's select search records. We've already set up our credentials, so we won't change that. And the resource will leave as record, operation will leave as search. From the base, let's select pizza place as the base. And for the table, let's select orders. And I won't change anything else, so let's run this node, and look at that. We get all the records back from our table. And if we go back to the canvas, we can see that five entries were selected. Now let's have a look at
[16:34] some of the most important nodes that you will use pretty much all the time in n8n. First, let's have a look at the filter node. Let's add a node, and instead of going to actions, let's have a look at data transformation. There are many transformation nodes offered by n8n, but in this video, I'll try to cover the most important ones. Let's start with the filter node. We can use the filter node to only process specific records from the previous node. On the left hand side, if we go to the table view,
[17:06] and we can just scoot up this view over here, we can see that several orders were returned. But what if we only wanted to process orders where the size is large? What we could do is add the size to the condition with a value of large, like so. And if I run this, you will notice on the right hand side that two records were kept and three were discarded. So in other words, only the entries with a size of large were kept. Now let's have a look at the order node.
[17:37] Let's add another node and let's search for sort. And let's add a field to sort by, and I want to sort by the client's name. And let's click on this step. And we can see that the names were sorted in ascending order. And if we change the order and run this again, these two records were swapped around. Great. Now I'm actually going to delete the sort node. We can keep the filter node. And now I'm going to show you one of the most versatile nodes in NNN and that's the set node.
[18:08] So let's add a new node. Let's search for set. The set node allows us to change the data in extremely interesting ways. So we can remove fields, change fields, or even add fields. Now let's keep this simple and simply enable include all other input fields. When I run this, we simply output the same values that we received on the left-hand side over here from the previous node. In fact, if I switch to table view, you will notice that these two records are identical.
[18:39] But let's assume we wanted to drop the created time column in this result. I'll actually disable this toggle. And all we need to do is drag and drop the fields that we want over here. So I'll add pizza and let's add size. Now, if I run this, we created a new table which excludes the created time. We can also manipulate data. So let's say we wanted to change the value of name to uppercase. NNN provides some built-in functions that we can call on these placeholders.
[19:11] So directly after name, if I enter period, this popup will be displayed with all the available functions for this value. So let's say I wanted to change the name to uppercase. If I now run this, the name is indeed transformed to uppercase values. Let's also have a look at adding a new field to this output structure. Let's say for argument's sake that within this table, we also had a column called summary which is dynamically created after the user submits to form.
[19:42] We can use the set module within NNN to create this new field. So instead of dragging a value from the left-hand side, I'm just going to click on this field over here. Let's give it a name like summary. And for the value, I can enter pretty much anything I want like hello world. And if I executed this, we will see that new column showing up in the output with this hard coded value. But instead, we want to dynamically populate this field. So I'm going to remove this hard coding.
[20:13] Let's switch over to expression and I'm going to click on this button to open this up in full screen mode. Now I want the summary to be something like Lara ordered a large pizza as an example. But now these values shouldn't be hard coded but should be dynamic instead. So instead of the text Lara, I'm going to drag the name from this previous module and paste it into here. Also note that you can grab values from other nodes as well
[20:43] but in it in safely assumes that you are referring to the values coming in from the previous node. So let's also remove lodge and it's drag in the lodge variable. It's also remove pizza and it's at the pizza value over here. And on the right-hand side, we do get a preview of the final result. It's closest window. Let's run this again. And this time the summary is dynamically populated. So now that we've added a summary to the order, let's update the records in
[21:13] air table with the summary. So after edit fields, let's add a new node and let's look for air table. Let's select create or update record. So let's select the base, which is pizza place. Let's select the table, which was orders. For the mapping, we'll select map each column manually. We can also select the column that it should match on, which should be the ID column. So we'll just leave that default value. Now for the values to update, let's simply grab the ID value.
[21:44] Let's also map the name, the pizza value, the size, as well as the new column that we created for summary. So let's go back to the canvas and let's keep this entire workflow as pin. Let's click on test workflow and let's see what happens. Okay, the workflow executed successfully and two items were processed. Let's go back to air table and we can see that these names were converted to uppercase and the summary was populated as well. Now let's have a look at the if module.
[22:15] I'm going to delete the folder module and instead I'm going to add a new node and that's going to be the if node. And let's have a look at this if node on the canvas. The if node has a true or false branch. So within the if node, we can specify a condition or a series of conditions. And if those conditions are met or true, then the true path will be followed. Otherwise the false path will be followed. Let's have a look at that. So let's say that if the
[22:46] size is equal to small, then the condition will be true. And if I run this module by itself, we can see that one item was indeed passed into the true path. And if we look at our data, that is because we only have one small pizza order. So as an example, let's say that if the pizza is small, then we'll set the summary to something like order was processed. But if the pizza is not small, then we'll do something else. So I'm going to copy the
[23:16] edit node and the air table node using control C and paste it with control V. And I'm going to attach the false root to this edit fields over here. So if the pizza is not small, then we're actually going to cancel the order. Order was canceled. Let's go back to the canvas and let's run this workflow. So yes, we can see that one item was passed to the true path and four items to the false path. And if we look at air table,
[23:47] we can see that the small order was processed and all other orders were canceled. Now let's have a look at the final note for this video. But first, if you find this video useful, then please hit the like button and subscribe to my channel for more innate end content. So the if node only provides two different outputs, true or false. But what if we wanted to follow different paths for the small, medium and large sizes? For multiple paths, we can use a different node called switch.
[24:17] So let's add the switch node and within switch, we can have multiple routes. So for value one, let's assign the value of size. And if the value is small, then this path will be followed. Let's add another route again, based on the size. And this time, if the value is medium, then we'll follow this route. Let's also create a route for large. So let's provide a value of large. If we go back to the canvas, we can see that there are multiple routes now,
[24:48] but these are not very readable. So let's rename these outputs. Let's call this one small. Let's call this one medium. And let's call this one large. And if we go back to the canvas now, this looks way better. So for all small pizzas, let's go to this route. For all medium pizzas, we can go to this route. Let's move these nodes around to make it a bit more readable. And I'm going to copy these two nodes as well. Let's move them up to over a year and let's connect the large path.
[25:19] So if the pizza is small, then we'll set the summary to order was processed. If the pizza is medium, then we'll set the summary to order was canceled. And for fun, if the order was large, we'll set the summary to processing the order, something like that. So let's go ahead and run this. So we can see that one item was passed to the small route, two items were passed to the medium route and two items to the large route. And if we look at air table, we can see that the records were indeed updated
[25:50] based on their size. I hope you enjoyed this video. And again, if you find this video useful, then please help me with the algorithm by hitting that like button. I'll see you in the next one. Bye-bye.