Understanding APIs in n8n (as a beginner)

Dr. Violet Howard explains APIs using a restaurant-waiter analogy, then walks through three n8n examples: fetching weather data with OpenWeatherMap, retrieving posts from JSONPlaceholder, and sending search queries to Tavily for AI summarization. She shows how n8n's built-in integrations save time versus manual HTTP requests.
Chapters
APIs may sound like tech jargon, but they're really the secret sauce behind everything that you do on the internet every day. In this video, I'm breaking down APIs so simply that anyone can understand them, and then we're going to hop into N8N and go through some examples. By the end, you'll see how APIs can transform your workflows, even if you're a complete beginner. Let's dive in. Okay, so today we're going to be understanding APIs, and we're going to have a specific tailored towards understanding APIs within N8N. N8N has a ton of integrations, so a lot of times you won't even need to use an API because they have built-in integrations for all the apps that you may use every day, like email, calendar, Twitter, LinkedIn, all that kind of stuff. But if you do need to access some sort of third-party API, you'll see how to do it in this video. First things first, what is an API? API stands for Application Programming Interface, and it's just a set of rules and protocols that allows different software applications to communicate with each other and send data back and forth, that sort of thing. Simply put, an API is what allows N8N to talk to your email, or for a calendar to talk to your N8N. So a quick real-world analogy, because everything's better with a real-world analogy. Let's pretend this guy right here is you, and you want to order food at a restaurant. So think of the API as the waiter in a restaurant. You tell the waiter what you want. The waiter then communicates your order to the kitchen or to the restaurant, and then the restaurant prepares the information that you wanted or the dish that you asked for, and then it takes the request back all the way to you. And returns the food to you, or not returns, but gives you the food. So that's sort of the real-world analogy. Hopefully that made sense. So we have two entities. We have you, and then we have the kitchen, and we just need a method for the two entities to be able to exchange information. That's an API. Now, why are APIs useful? APIs enable seamless integration between different software systems like we talked about, and this allows them to share data and functionalities between each other. So this is important for building systems or applications because it allows us to leverage existing services rather than having to build things from scratch. So let's say we wanted to convert miles to kilometers. Instead of having to build out that calculation, we could just leverage a different third-party API that already does that. We could just send information to it and then wait for the response back rather than having to, you know, build out that whole infrastructure from scratch. Okay, so if the concept hasn't stuck yet, let's look at some real-world examples. So weather data integration. Many websites and apps display current weather information by leveraging APIs, provided by weather services. So for example, a travel app may show you real-time weather updates because it's fetching data from a weather API. Then we have social media sharing. So when you share a news article directly to Facebook or X from a website, you're using that social media platform's API. The API allows the website to communicate with a social media platform to post on your behalf. Then we have stuff like payment processing. You know, e-commerce sites often use payment gateways like PayPal or Stripe. and these services provide APIs that handle the complexities of payment processing. These enable the e-commerce site to securely process your transactions without handling sensitive payment information directly because they just use the API to talk to each other. Then our last real-world example, third-party logins, something you've done probably a million times. Websites often allow users to log in using their Google or Facebook accounts, and this is facilitated by the respective platform's API, which authenticates the user, grants access without having to create a new account. Okay, moving on to API methods. This stuff may look like it's gonna get a little technical, but it's really not. You've got different methods here, and I wanted to point out that GET and POST are underlined. This is because 99% of the time that you are accessing some sort of API endpoint, you're going to be using a GET or a POST. But let's break down all of them just in case. So a GET is when you want to retrieve data. So an action for this could be like, give me the current weather, when you're reaching out to a weather API. And an analogy for this is just reading a book. You're just getting information. Then we have a POST, which is you're sending data to, you know, create something or get something back. You're sending information. So an action would be, here's policy information. And an analogy for this would be you're sending a letter. Then we've got PUT, which is if you want to update existing data. So you would be replacing this completely, and that would be like replacing pages within a book. We've got PATCH, which is partially updating data, you know, just kind of patching it. You'd be tweaking this part, and that would be like editing a single word within a book or within a page. Then we've got DELETE, which is to remove data. Obviously, the action here would just be erase this. It would be like tearing out a page out of a book. And so those are pretty much the main 5 methods of REST APIs, which I'll talk about REST APIs. Okay, so REST API stands for Representational State Transfer API. And it's just a way for different software systems to communicate over the web using a standard HTTP request like GET, POST, PUT, and DELETE. So it organizes its data into resources, which is accessible through a unique URL. And this will make a lot more sense once we get into N8N and we actually look at these URLs. But basically, for every action you have, there's going to be a different API endpoint, which is just the URL that you would see up top when you're like typing something into Google. There's going to be different parameters at the end of them based on what type of action you want to take. Like I said, it'll make more sense when we get into it. Anyways, REST APIs are stateless, which just means that each request is independent. They follow consistent patterns, which makes them really simple and scalable, and also they're widely supported for different integrations across various platforms. Now we're going to get into some examples within N8N, and this is really crucial because APIs play such an important role when you're sort of automating workflows. For example, you could have a workflow that triggers when you receive an email, which would be using the email service's API to get information back from that email provider. Then you could process the content, and then if you want to store it into a database, you would be sending a POST request to that database's API in order to send information to the database from N8N. So this interconnectedness allows for efficient automation, integrating different services, and really removing the manual touchpoint out of that process. So like I said, understanding APIs is very fundamental for creating effective workflows, and once you get a good understanding of it, the possibilities of what you can do in n8n are truly endless. Okay, so for example number 1, we're going to be sending a GET request to OpenWeatherMap API. So we're going to be asking for information back about the current weather in some sort of city. So in n8n, when you want to access an API endpoint, you're going to do that through an HTTP Request node. So you can see that we have that right here. If you come into the plus button and type in HTTP, you can see HTTP request. So that's what we've got set up right here. If we click into it, we can see that we have a method. So our method here is GET, because like I said, we want to access this URL of OpenWeatherMap, and we want to get information back. So anytime that you're accessing a third-party API, you want to look at the documentation for that API. Their documentation are going to show you the different endpoints, it's going to show you the different parameters, and it's going to show you the way that you can make the request to either get the information you want or send the information you want. So what we're looking at right here is the OpenWeatherMap API's documentation. So as you can see, what we want to do is call current weather data. This is showing us how to make an API call. This is the API endpoint that we need, and then it's showing us parameters to send off in our request. So the first thing you notice is that we have 3 required parameters. We have the latitude, the longitude, and the app ID, which is just— we need to enter in an API key basically to let OpenWeatherMap know that we have access to this information. So you can see this is the, the information that we need. So we copy this link, we put this within our URL, and you can see I filled in the latitude, the longitude, and I filled in the API key. So based on this information, that's the stuff that's required. And then we also see that there's optional fields. So you could select the mode, you could select the units. And so what I did was I grabbed the units. It's a parameter that we're putting in, and and I wanted the units to be shown imperial. So in here you can see we have, um, here, actually let me just make this a little bigger. So we have lat right there, 41. We have longitude, which is 87. We have units, which I put imperial, and then we have our app ID, which is just our API key. And so if you want to follow along, you'll go to OpenWeather, make an account, um, and then when you go to your account up here, you'll click on my API keys, and then you'll copy this value right here. And that is what's going to go in the API key section of this endpoint request. So now that I filled in this information, we will hit test step. And you can see that we get the information back. And this is all the information I put in the latitude and longitude of Chicago. And so this was our request. It successfully went through. We sent that off to OpenWeatherMap, and then it came back to us with information. So then all I did was I just hooked up a message model to summarize that information we're getting, um, just so we can show it in a clean format. So basically, we sent off that request, and then we end up getting, hello there, in lovely Chicago today, the sky is draped in cozy overcast clouds, um, calm and soft vibe, um, about 48.9°F, the air is humid 53%, gentle breeze, blah blah blah. So, um, that's all that's going on here. Real quick, just wanted to say that this workflow, as you can see, we're going to be running through some different examples, But this workflow will be available for download in my free school community. Link for that will be down in the description. If you want to go a little farther with N8N, you want to hop on live weekly calls with me and members of the community, check out my paid community. Also will be linked down below. And then if you're looking for me to help you build out this sort of stuff in your business or AI consulting, then book a call on my website, which is also linked down below. But let's get back to the video. So what I wanted to show you here is, yes, we just accessed OpenWeatherMap API and we got the weather. But what's really cool is that N8N obviously has a ton of integrations, so they actually have an integration for OpenWeatherMap API. You come in here, um, this is where you put your API key. You create a credential. Um, our operation is we're looking for weather. We have a format. We can select the location. So this is doing the exact same thing that we just did within our HTTP request. As you can see, we're getting back the exact same information for Chicago, but it just made it a lot easier because we have like drag and drop fields, or not drag and drop, we have collapsible fields that we can just choose information from. Rather than having to configure an HTTP request with different parameters and different credentials. So most of the time, um, N8N is going to have a lot of integrations, but that's why I said if you need to access some sort of third-party API, you'll go to the docs and then you'll just have to read about how you configure your request. Okay, example number 2, we're going to do another GET request and we're using JSON Placeholder API, which is just a free REST API online where you can just, you know, test out how it works when you want to get information back. So if we go to JSON Placeholder documentation, we can see, um, you know, the specs that we need. So this is the, um, this is the API endpoint we're accessing: https://jsonplaceholder.typecode.com. And so that's the endpoint that we want to access. And then from there, we have different things that we can do. So if we put /posts after it, we'll get 100 posts. If we put /comments after it, we'll get 500 comments. So Let's go back in here. You can see right now all I did is just— I have— I just have the base URL, and we'll hit test step, and we're going to get a ton of random HTML that's just not very readable or important to us. So as you remember, in here we can see there's different resources we can access within JSON Placeholder. So if we want to grab /posts, we throw this at the end of our API endpoint that we're trying to access. Now we have a new unique REST API. We'll hit test step, and now we can see we got 100 items, and we basically just got 100 posts of gibberish. As you can see, this is all just fake information. Hopping back into the placeholder, we can see that if we did a different one, we did /comments, we're going to get 500 comments back. We'll hop back into here, change our API endpoint that we're accessing, and now we're getting comments back. We're getting 500 comments back from JSON Placeholder. So This is just an example of, you know, another way that you can set up your URL, different ways that you have different endpoints to access. In this case, we didn't really have to fill in any parameters, but a lot of times you will have to do that, usually something with like an API key or different information. You'll see in this next example, we're going to be sending information with a POST request to get articles back. Now in this final example, I said we were going to be doing a POST request, so we're going to be sending a request to Tavelly, which is just kind of a super cool search API. We'll be sending information over as far as what we want to look for, and then it's going to go out, get that information based on the information we send it, and then bring back some articles for us. So I'll hit this test workflow, we can see it happen real quick. We just sent off a query, it's going to search the internet based on our query and then summarize the articles for us so we can read it better. But let's hop into the actual POST request. So if we go back into Tably, um, we can see the documentation for API reference for the REST API, of course. This is the base URL. As you can see, the Taveley Search and Extract REST API can be accessed through this base URL. So we put this base URL right here into our Taveley, and then all we had to do was add the endpoint of /search because we are searching for specific information. So we added that endpoint, which is a POST request, and now we can see the different parameters that we need. So the two required parameters are query which is the search query that you want to execute within Tavily. So if you were to go to Google and you were to type in something, that's the query that we're sending to Tavily. And then of course we need an API key, and that's also required. And then we have optional things. So we have like max results, if you only want to get 5 results back, if you only want to get 3 results back, if you want to include images, all this kind of stuff. Um, we also did— where is it— topic. So for topic, we could put general or news. And so I went in there and put news, and I'll show you guys this. So query, API key, topic, and I think we also maybe include max results. But here is our POST request. So we're sending over our API key, of course. That just basically gives us access to hit this third-party API. If I didn't put this in, it would just deny our request. The query, we're looking for top trends in AI. We wanted to put topic equals news, and then we also put max results equals 3. So we're going to be getting really relevant news articles from Tavaly, and it's also going to only give us 3 results because this is the information we're sending it to actually go make that request, and then it's going to send us the results back. So, um, as you can see, we already got— we already had this executed. So then we had OpenAI take those articles and summarize them for us just so it's easier for us to read. As you can see, we got 3 articles back. Actually, let me show you in here. It's a little easier to see. Right here we have URL 1, URL 2, URL 3. So those are the 3 articles we got back. And then we just had it summarize it for us. So, um, the articles collectively emphasize the pervasive impact of artificial intelligence across various sectors, highlighting its transformative role. The first article explains blank. The second article discusses blank. The third article— lastly, the third article previews the blah blah blah. Okay, so as you can see, it took those 3 articles, and summarize them, but the main point was just that we sent off this request about AI. Um, we wanted news and we wanted 3 results, and that's how it came back for us. Now that we understand what APIs are, I just wanted to touch on how cool it is that N8N has so many integrations. So something like Gmail, if we wanted to send a message, we have this right here that we can configure. All we have to do is set up the to, the subject, the message, and the operation. Rather than setting up an HTTP request where we're accessing Gmail and then within Gmail, we're accessing an endpoint to send a message. And then within that endpoint, we're setting up parameters of who's going to, what's the subject, what's it gonna say, um, all that kind of stuff. Same thing with Airtable, Sheets, Calendar, and all of these other apps that you can take action in, in n8n, which there's just a ton of integrations. All of these, if they didn't have these integrations where you could just go in and really easily configure what you're looking for, you'd have to set up an HTTP request with different endpoints and different parameters. So it's really cool that they have all these integrations, but it's good to understand that when you're doing these things, all you're doing is you're making an HTTP request to— or sorry, you're making a request to an endpoint, an API endpoint. So it's really good to understand that. And the 3 main benefits here are these are really easy to use, it's going to save you a lot of time, and it's going to save you a lot of errors. Because, you know, when you get into the documentation of looking at API endpoints, you may have a few headaches as far as, um, your API key had an extra space in it so it didn't work, or your parameters weren't configured correctly. Stuff like that. So these integrations are, um, really lifesavers. Anyways, that's going to be it for this video. Like I said, if you want to get in here and just play around with these examples I made, the workflow will be available for download in the FreeSchool community, linked in the description. But I really appreciate you guys making it all the way to the end of this one. If you enjoyed the video, please give it a like, definitely helps me out. And I will see you guys in the next one. Thanks.










