APIs for AI Agents: The Only Beginner’s Guide You’ll Ever Need (n8n)

Dr. Violet Howard teaches how to connect APIs to AI agents in n8n, using OpenWeatherMap and Perplexity as examples. You'll learn the five parts of an HTTP request, how to configure authentication with bearer tokens, and how to turn API calls into agent tools that run dynamically at runtime.
Chapters
If you're building AI agents, but you don't really understand what an API is or how to use them, don't worry. You're not alone. I was in that exact same spot not too long ago. I'm not a programmer. I don't know how to code, but I've been teaching tens of thousands of people how to build real AI systems. And what changed the game for me was when I understood how to use APIs. So in this video, I'm going to break it down as simple as possible. No technical jargon. And by the end, you'll be confidently setting up API calls within your own Agentic workflows. Let's make this easy. So the purpose of this video is to understand how to set up your own requests so you can access any API, because that's where the power truly comes in. And before we get into N8N and we set up a couple live examples and I show you guys my thought process when I'm setting up these API calls, first I thought it would just be important to understand what an API really is. And APIs are so, so powerful because let's say we're building agents within N8N. Basically, we can only do things within N8N's environment unless we use an API to access some sort of server. So whether that's like a Gmail or a HubSpot or Airtable, whatever we want to access that's outside of any of N's own environment, we have to use an API call to do so. And so that's why at the end of this video, when you completely understand how to set up any API call you need, it's going to be a complete game changer for your workflows, and it's also going to unlock pretty much unlimited possibilities. All right, now that we understand why APIs are important, let's talk about what they actually do. So API stands for Application Programming Interface, and at the highest level in the most simple terms, it's just a way for two systems to talk to each other. So N8N and whatever other system we want to use in our automations. So keeping it relevant to us, it's our N8N AI agent and whatever we want it to interact with. Okay, so I said we're gonna make this as simple as possible, so let's do it. What we have here is just a scenario where we go to a restaurant. So this is us right here, and what we do is we sit down and we look at the menu and we look at what food that the restaurant has to offer. And then when we're ready to order, we don't talk directly to the kitchen or the chefs in the kitchen, we talk to the waiter. So we'd basically look at the menu, we'd understand what we want, then we would talk to the waiter and say, hey, I want the chicken parm. The waiter would then take our order and deliver it to the kitchen. And after the kitchen sees the request that we made and they understand, okay, this person wants chicken parm, I'm gonna grab the chicken parm, not the salmon, and then we're basically gonna feed this back down the line through the waiter all the way back to the person who ordered it in the first place. And so that's how you can see we use an HTTP request to talk to the API endpoints and receive the data that we want. And so now a little bit more of a technical example of how this works in N8N. Okay, so here is our AI agent, and when it wants to interact with a service, it first has to look at that service's API documentation to see what is offered. Once we understand that, we'll read that and we'll be ready to make our request, and we will make that request using an HTTP request. From there, that HTTP request will take our information and send it to the API endpoints, The endpoint will look at what we ordered and it will say, okay, this person wants this data, so I'm going to go grab that. I'm going to send it back, send it back to the HTTP request. And then the HTTP request is actually what delivers us back the data that we asked. And we know that it was available because we had to look at the API documentation first. So I hope that helps. I think that looking at it visually makes a lot more sense, especially when you hear, you know, HTTP API endpoint, all this kind of stuff. But really it's just going to be this simple. So now let me show an example of what actually this looks like in n8n and when you would use one and when you wouldn't need to use one. So here we have two examples where we're accessing a service called OpenWeatherMap, which basically just lets us grab the weather data from anywhere in the world. And so on the left, what we're doing is we're using OpenWeather's native integration within n8n. And so what I mean by native integration is just that when we go into n8n and we click on the plus button to add an app and we want to see like, you know, the different integrations, it has Airtable, it has Affinity, it has Airtable, it has all these AWS things. It has a ton of native integrations. And all that a native integration is is an HTTP request, but it's just like wrapped up nicely in a UI for us to basically fill in different parameters. And so once you realize that, it really clears everything up because the only time you actually need to use an HTTP request is if the service you want to use is not listed in this list of all the native integrations. Anyways, let me show you what I mean by that. So like I said, on the left we have OpenWeatherMap's native integration. So basically what we're doing here is we're sending over, okay, I'm using OpenWeatherMap, I'm gonna put in the latitude and the longitude of the city that I'm I'm looking for. And as you can see over here, what we get back is Chicago, as well as a bunch of information about the current weather in Chicago. And so if you were to fill this out, it's super, super intuitive, right? All you do is put in the lat and long, you choose your format as far as imperial or metric, and then you get back data. And that's the exact same thing we're doing over here where we use an HTTP request to talk to OpenWeather's API endpoint. And so this is just— looks a little more scary and intimidating because we have to set this up ourselves. But if we zoom in, we can see it's pretty simple. We're making a GET request to OpenWeatherMap's URL endpoint, and then we're putting over the lat and the long, which is basically the exact same from the one on the left. And then, as you can see, we get the same information back about Chicago and then some weather information about Chicago. And so the purpose of that was just to show you guys that these native integrations, all we're doing is we're accessing some sort of API endpoint. It just looks simpler and easier, and there's a nice user interface for us. Rather than setting everything up manually. Okay, so hopefully that's starting to make a little more sense. Let's move down here to the way that I think about setting up these HTTP requests, which is we're basically just setting up filters and making selections. All we're doing is we're saying, okay, I wanna access server X. When I access server X, I need to tell it basically what do I want from you? So it's the same way when you're gonna order some pizza, you have to first think about which pizza shop do I wanna call? And then once you call them, it's like, okay, I need to actually order something. It has to be small, medium, large. It has to be pepperoni or cheese. You have to tell it what you want, and then they will send you the data back that you asked for. So when we're setting these up, we basically have like 5 main things to look out for. The first one you have to do every time, which is a method, and the 2 most common are gonna be a GET or a POST. Typically a GET is when you're just gonna access an endpoint and you don't have to send over any information, you're just gonna get something back. But a POST is when you're gonna send over certain parameters and certain data and say, okay, using this information, send me back what I'm asking for. The great news is, and I'll show you later when we get into N8N to actually do a live example, it'll always tell you to say, you know, is this a GET or a POST? Then the next thing is the endpoint. You have to tell it like which website or, you know, which endpoints you want to actually access, which URL. From there, we have 3 different parameters to set up, and also just realize that this one should say body parameters. But this used to be the most confusing part to me, but it's really not too bad at all. So let's break it down. So keep in mind, when we're looking at that menu, that API documentation, it's always going to basically tell us, okay, here are your query parameters, here are your header parameters, and here are your body parameters. So as long as you understand how to read the documentation, you'll be just fine. But typically the difference here is that when you're setting up query parameters, this is basically just saying a few filters. So if you search pizza into Google, it'll come google.com/search, which would be Google's endpoint, and then we would have a question mark and then q equals and then a bunch of different filters. So as you can see right here, the first filter is just q equals pizza. And the Q is, you know, it stands for query parameters. And you don't even have to understand that. That's just me showing you kind of like a real example of how that works. From there, we have to set up a header parameter, which is pretty much always going to exist. And I basically just think of header parameters as, you know, authorizing myself. So usually when you're doing some sort of API where you have to pay, you have to get a unique API key, and then you'll send that key. And if you don't put your key in, then you're not gonna be able to get the data back. So like if you're ordering a pizza and you don't give them your credit card information, they're not going to send you a pizza. And usually an API key is something you want to keep secret because let's say, you know, you put $10 into some sort of API that's going to create images for you. If that key gets leaked, then anyone could use that key and could go create images for themselves for free, but they'd be running down your credits. And these can come in different forms, but I just wanted to show you a really common one is, you know, you'll have your key-value pairs where you'll put authorization as the name, and then in the value you'll put bearer space your API key. Or in the name, you could just put API_KEY, and then in the value, you'd put your API key. But once again, the API documentation will tell you how to configure all this. And then finally, the body parameters. If you need to send something over to get something back, let's say we're, you know, making an API call to our CRM and we want to get back information about John. We could send over something like name equals John. The server would then grab all records that have name equal John, and then it would send them back to you. So those are basically like the 5 main things to look out for when you're reading through API documentation and setting up your HTTP request. But the beautiful thing about living in 2025 is that we now have the most beautiful thing in the world, which is a curl command. And so what a curl command is, is it lets you hit copy, and then you basically can just import that curl into n8n, and it will pretty much set up the request for you. Then at that point, it really is just like putting in your own API key and tweaking a few things if you want to. So let's take a look at this curl statement for a service called Tavelly. As you can see, that's the endpoint is api.tavelly.com. All this basically does is it lets you search the internet. So you can see here, this curl statement tells us pretty much everything we need to know to use this. So it's telling us that it's going to be a POST. It's showing us the API endpoint that we're going to be accessing. It shows us how to set up our header. So that's going to be authorization, and then it's going to be bearer space API token. It's basically just telling us that we're gonna get this back in JSON format. And then you can see all of these different key-value pairs right here in the data section. And these are basically gonna be body parameters where we can say, you know, query is, who is Leo Messi? So that's what we'd be searching the internet for. We have topic equals general. We have search depth equals basic. So hopefully you can see all of these are just different filters where we can choose, okay, do we want, you know, do we want 1 max result or do we want 4? Or do we have a time range or do we not? So this is really just, at the end of the day, it's basically like ordering DoorDash. Because what we would have up here is, you know, like what actual restaurant do we want to order food from? We would put in our credit card information. We would say, do we want this to be delivered to us? Do we want to pick it up? We would basically say, you know, do you want a cheeseburger, no pickles, no onions? Like what are the different things that you want to flip? Do you want a side? Do you want fries or do you want salad? Like what do you want? And so once you get into this mindset where all I have to do is understand this documentation and just tweak these little things to get back what I want. It makes setting up API calls so much easier. And if another thing that kind of intimidates you is the aspect of JSON, it shouldn't, because all it is is a key-value pair like we kind of talked about. You know, this is JSON right here, and you're going to send your body parameter over as JSON, and you're also going to get back JSON. So the more and more you use it, you're going to recognize like how easy it is to set up. So anyways, I hope that that made sense and broke it down pretty simply. Now that we've seen like how it all works, it's going to be really valuable to get into N8N. I'm going to open up an API documentation and we're just going to set up a few requests together and we'll see how it works. Okay, so here's the example. You know, I did OpenWeather's native integration and then also OpenWeather as an HTTP request. And you could see it was like basically the exact same thing. So let's say that what we want to do is we want to use Perplexity, which if you guys don't know what Perplexity is, it is basically, you know, kind of similar to ChatGPT, but it has really good like internet search and research. So let's say we wanted to use this and hook it up to an AI agent so it can do web search for us. But as you can see, if I type in Perplexity, there's no native integration for Perplexity. So that basically signals to us, okay, we can only access Perplexity using an HTTP request. And real quick side note, if you're ever thinking to yourself, hmm, I wonder if I can have my agent interact with blank. The answer is yes, if there's API documentation and all you have to do typically to find out if there's API documentation. Is just come in here and be like, you know, Gmail API documentation. And then we can see Gmail API is a RESTful API, which means it has an API and we can use it within our automations. Anyways, getting back to this example of setting up a Perplexity HTTP request, we have our HTTP request right here and it's left completely blank. So as you can see, we have our method, we have our endpoint, we have query, header, and body parameters, but nothing has been set up yet. So what we need to do is we would head over to Perplexity, as you can see right here, and at the bottom there's this little thing called API. So I'm going to click on that, and this opens up this little page. And so what I have here is Perplexity's API. If I click on developer docs, and then right here I have API reference, which is integrate the API into your workflows, which is exactly what we want to do. This page is where people might get confused, and it looks a little bit intimidating, but hopefully this breakdown will show you how you can understand any API doc, especially if there's a curl command. So all I'm going to do first of all is I'm just going to right away, hit copy and make sure, you know, you're in curl. If you're in Python, it's not the same. So click on curl. I copied this curl command and I'm going to come back into N8N, hit import curl, and all I have to do is paste, click import. And basically what you're going to see is this HTTP request is going to get basically populated for us. So now we have the method has been changed to POST. We have the correct URL, which is the API endpoint, which basically is telling this node, okay, we're going to use Perplexity's API. You can see that the curl had no query parameters, so that's left off. It did turn on headers, which is basically just having us put our API key in there. And then of course we have the JSON body that we need to send over. Okay, so at this point what I would do is now that we have this set up, we know we just need to put in a few things of our own. So the first thing to tackle is how do we actually authorize ourselves into Perplexity? All right, so I'm back in Perplexity. I'm gonna go to my account and click on settings. And then all I'm gonna do is basically I need to find where I can get my API key. So on the left-hand side, if I go all the way down, I can see API keys. So I'll click on that. And all this is going to do is this shows my API key right here. So I'll have to click on this, hit copy, come back into n8n. And then all I'm going to do is I'm going to just delete where this says token, but I'm going to make sure to leave a space after bearer and hit paste. So now this basically authorizes ourselves to use Perplexity's endpoint. And now if we look down at the body request, we can see we have this thing set up for us already. So if I hit test step, this is real quick, gonna make a request over. It just hit Perplexity's endpoint, and as you can see, it came back with data. And what this did is it basically searched Perplexity for how many stars are there in our galaxy. And that's where right here we can see the Milky Way galaxy, which is our galaxy, is estimated to contain between 100 billion and 400 billion stars, blah, blah, blah. So we know basically, okay, if we want to change how this endpoint works, what data we're going to get back, this right here is where we would change our request. If we go back into the documentation, we can see what else we have to set up. So the first thing to notice is that there's a few things that are required and then some things that are not. So right here we have, you know, authorization, that's always required. The model is always required, like which Perplexity model are we going to use. The messages are always required. So this is basically a mix of a system message and a user message. So here the example is be precise and concise, and then the user message is how many stars are there in the galaxy. So if I came back here and I said, you know, be funny in your answer. So I'm basically telling this model how to act. And then instead of how many stars are there in the galaxy, I'm just going to say, how long do cows live? And I'll make another request off to Perplexity. So you can see what comes back is this longer content. So it's not being precise and concise. And it says, so you're wondering how long cows live? Well, let's move into the details. So as you can see, it's being Funny. Okay, back into the API documentation. We have a few other things that we could configure, but notice how these aren't required the same way that these ones are. So we have max tokens. We could basically put in an integer and say, how many tokens do you want to use at the maximum? We could change the temperature, which is, you know, like how random the response would be. And this one says, you know, it has to be between 0 and 2. And as we keep scrolling down, you can see that there's a ton of other little levers that we can just tweak a little bit to change the type of response that we get back from Perplexity. And so once you start to read more and more API documentation, you can understand how you're really in control of what you get back from the server. And also you can see like, you know, sometimes you have to send over booleans, which is basically just true or false. Sometimes you can only send over numbers. Sometimes you can only send over strings. And sometimes it'll tell you, you know, like what will this value default to? And also what are the only accepted values that you actually could fill out? So for example, if we go back to this temperature setting, we can see it has to be a number. And if you don't fill that out, it's going to be 0.2. But we can also see that if you do fill this out, it has to be between 0 or 2, otherwise it's not going to work. Okay, cool. So that's basically how it works. We just set up an HTTP request and we change the system prompt and we change the user prompt, and that's how we can customize this thing to work for us. And that's really cool as a node because we can set up, you know, a workflow to pass over some sort of variable into this request so it searches the web for something different every time. But now let's say we want to give our agent access to this tool, and the agent will decide, what am I going to search the web for based on what the human asks me? So it's pretty much the exact same process. We'll click on Add a Tool, and we're going to add an HTTP request tool only because Perplexity doesn't have a native integration. And then once again, you can see we have an Import Curl button. So if I click on this and I just import that same curl that we did last time, once again, it fills out this whole thing for us. So we have POST, we have the Perplexity endpoint. We have our authorization bearer, but notice we have to put in our token once again. And so a cool little hack is, let's say, you know, you're going to use Perplexity a lot. Rather than having to go grab your API key every single time, what we can do is we can just send it over right here in the authentication tab. So let me show you what I mean by that. If I click into authentication, I can click on generic credential type. And then from here, I can basically choose, okay, is this a basic auth, a bearer auth, all this kind of stuff. A lot of times it's just going to be header auth, so that's why we know right here we can click on header auth. And as you can see, we know that because we're sending this over as a header parameter, and we just did this earlier and it worked. So as you can see, I have header auths already set up. I probably already have a Perplexity one set up right here, but I'm just going to go ahead and create a new one with you guys to show you how this works. So I just create a new header auth, and all we have to do is the exact same thing that we had down in the request that we just sent over, which means in the name we're just gonna type in Authorization with a capital A. And once again, we can see in the API docs, this is how you do it. So Authorization, and then we can see that the value has to be capital B Bearer space API token. So I'm just gonna come into here, Bearer space API token. And then all I have to do is, you know, first of all, name this so we can save it. And then if I hit save, now every single time we wanna use Perplexity's endpoint, we already have our credentials saved. So that's great. And then we can turn off the headers down here because we don't need to send it over twice. So now all we have to do is change this body request a little bit just to make it more dynamic. So in order to make it dynamic, the first thing we have to do is change this to an expression. Now we can see that we can basically add a variable in here, and what we can do is we can add a variable that basically just tells the AI model, the AI agent, here is where you're going to send over your internet search query. And so we already know that all that, that is, is the user content right here. So if I delete this, and basically if I do two curly braces, and then within the curly braces I do a dollar sign and I type in from, I can grab a fromAI function. And this fromAI function just indicates to the AI agent, I need to choose something to send over here. And you guys will see an example and it will make more sense. I also did a full video breaking this down, so if you want to see that, I'll tag it right up here. Anyways, as you can see, all we have to really do is enter in a key. So I'm just going to do, you know, two quotes and within the quote I'm going to put in search term. And so now the agent will be reading this and say, okay, whenever the user interacts with me and I know I need to search the internet, I'm just going to fill this whole thing in with the search term. So now that that's set up, I'm just going to change this request to, um, actually I'm just going to call it web search to make that super intuitive for the AI agent. And now what we're going to do is we are going to talk to the agent and see if it can actually search the web. Okay, so I'm asking the AI agent to search the web for the best movies. It's going to think about it. It's going to use this tool right here, and then we'll basically get to go in there and we can see what it filled in in that search term placeholder that we gave it. So first of all, the answer it gave us was IMDb top 250, Rotten Tomatoes, all this kind of stuff, right? So that's movie information that we just got from Perplexity. And what I can do is click into the tool and we can see in the top left, it filled out search term with best movies. and we can even see that in action if we come down to the body request that it sent over and we expand this. We can see on the right-hand side in the result panel, this is the JSON body that it sent over to Perplexity, and it filled it in with best movies. And then of course, what we got back was our content from Perplexity, which is, you know, here are some of the best movies across major platforms. All right, then real quick before we wrap up here, I just wanted to talk about some common responses that you can get from your HTTP requests. So the rule of thumb to follow is if you get data back and you get a 200, you're good. Sometimes you'll get a response back, but you won't explicitly see a 200 message. But if you're getting the data back, then you're good to go. And a quick example of this is down here we have that HTTP request which we went over earlier in this video where we went to OpenWeatherMaps API. And you can see down here we got code 200 and there's data coming back. And 200 is good. That's a success code. Now, if you get a request in the 400s, that means that you probably set up the request wrong. So 400 bad request, that could mean that your JSON's invalid. It could just mean that you have like an extra quotation mark or you have, you know, an extra comma, something as silly as that. So let me show a quick example of that. We're going to test this workflow, and what I'm doing is I'm trying to send over a query to Tavelly, and you can see what we get is an error that says JSON parameter needs to be valid JSON, and this would be a 400 error. And the issue here is if we go into the JSON body that we're trying to send over, you can see in the result panel we're trying to send over a query that has basically two sets of quotation marks, if you can see that. But here's the great news about JSON. It is so universally used and it's been around for so long that we could basically just copy the result over to ChatGPT, paste it in here and say, I'm getting an error message that says JSON parameter needs to be valid JSON. What's wrong with my JSON? And as you can see, it says the issue with your JSON is the use of double quotes around the string value in this line. So now we'd be able to go fix that. And if we go back into the workflow, We take away these double quotes right here, test the step again. Now you can see it's spinning and it's going to work, and we should get back some information about pineapples on pizza. Another common error you could run into is a 401, meaning unauthorized. This typically just means that your API key is wrong. You could also get a 403, which is forbidden. That just means that maybe your account doesn't have access to this data that you're requesting or something like that. And then another one you can get is a 404, which sometimes you'll get that if you type in a URL that doesn't exist. It just means this doesn't exist, we can't find it. And a lot of times when you're looking at the actual API documentation that you want to set up a request to— so here's an example with Tavelly— it'll show you what typical responses could look like. So here's one where, you know, we're using Tavelly to search for who is Leo Messi. This was an example we looked at earlier. And with a 200 response, we are getting back like a query, an answer, results, stuff like that. We could also see we could get a 400, which would be for bad request, you know, invalid topic. We could have a 401, which means invalid API key. We could get all these other ones like 429, 432, but in general, 400 is bad. And then even worse is a 500, and this just basically means something's wrong with the server. Maybe it doesn't exist anymore, or there's a bug on the server side. But the good news about a 500 is it's not your fault. You didn't set up the request wrong. It just means something's wrong with the server. And it's really important to know that because if you think you did something wrong, but it's really not your fault at all, you may be banging your head against the wall for hours. So anyways, what I wanted to highlight here is there's never just like a one-size-fits-all, I know how to set up this one API call so I can just set up every single other API call the exact same way. The key is to really understand how do you read the API documentation, how do you set up your body parameters and your different header parameters, and then if you start to run into issues, the key is understanding and actually reading the error message that you're getting back and adjusting from there. All right, so that's gonna do it for this video. Hopefully this has left you feeling a lot more comfortable with diving into API documentation, walking through it just step by step, using those curl commands, and really just understanding all I'm doing is I'm setting up filters and levers here. I don't have to get super confused. It's really not that technical. I'm pretty much in complete control over what my API is gonna send me back, the same way I'm in complete control when I'm, you know, ordering something on DoorDash or ordering something on Amazon, whatever it is. And if you wanna dive even deeper into APIs and HTTP requests, or if you wanna be able to have some tech support whenever you want, then definitely check out my paid community. The link for that is down in the description. We have a great community of over 1,400 members who are building with N8N every day. I also just launched these two courses within this community where we have Agent Zero is like the foundational knowledge you need to actually automate processes. And then 10 Hours to 10 Seconds where we pretty much go over, you know, from step one, picking a process into actually automating it. And obviously there's some more resources in here about APIs. Anyways, that's gonna do it for this one. Really appreciate you guys making it to the end of the video. As always, If you learned something new or you appreciated this video, please give it a like. Definitely helps me out a ton, and I'll see you guys in the next one. Thanks so much, everyone.










