# Using the HTTP node - smamudhan

## Метаданные

- **Канал:** n8n
- **YouTube:** https://www.youtube.com/watch?v=Lfd23yFKyUo
- **Дата:** 01.05.2024
- **Длительность:** 20:14
- **Просмотры:** 5,300

## Описание

Learn what APIs are and how to access them with the n8n HTTP node in this presentation by community member smamudhan. 

This presentation was part of the April 12 hangout - see the full video here: https://www.youtube.com/watch?v=K9P9phm33m4

## Содержание

### [0:00](https://www.youtube.com/watch?v=Lfd23yFKyUo) Segment 1 (00:00 - 05:00)

hello everyone I am Aman and uh I have been uh a longtime user of inat since the early days and so I think one of the most versatile nodes is the HTTP node right um You can do a lot with it but um today we are specifically going to look at uh two different uh problems or two different cases where the HTTP node becomes really useful and that's when um that's when you want to use it to implement or you know add a function to your workflow that an existing node does not already have and also when you want to say you know bring some data in or talk to another application for which you know there is no native n and node right and the HTTP node is obviously not limited to this functionality and you can do other things with it like web scraping but today this is what we're focusing on um so let's jump in but before we go in um one thing quick thing that most of you may already be familiar with but is worth mentioning is a quick refresher on apis so very simply put an API is uh is a way for you know different applications to talk to each other and you usually it is you know through a standardized format which these days tends to be you know Json and um there's of different types of apis but what is most relevant here today is HTTP or you know restful HTTP apis and there are some methods that you can use to interact with apis and I have listed some most common ones that you know are most frequently used and um you you can see them listed here so there's get which is normally used to read data from an API post which is used to kind of you know ask a question or send data or write data using an API and often you receive a response you know for the data that you send uh a put and a patch are both very similar a put request is used to replace existing data that is you know that the API is serving to you uh a patch is to a patch requ can be sent to update data and delete is very self-explanatory it can be used to you know delete data and this becomes important because um standards compliant apis all follow these um these request patterns and those are what we will be using uh in our examples and when you build a workflow you will need to set these up you know to talk to these different services that you want to connect with your workflow right and so I think uh it's easy to break this down into a set of Steps A playbook for you to follow if you will uh so the first thing that you want to do uh say you have um you have an application and you want to do something with it that you know n10 does not currently support the first thing you want to do is find out if there is an API right and uh you can do this by simply going in to the uh application documentation uh or the website of you know the service that you're trying to connect to and you know start looking for um API documentation and the next thing you want to do is once you've determined that there is an API for you to connect to an0 you want to make sure that um there is some kind most apis Implement some kind of authentication so you want to understand how to authenticate with that API in case it is necessary the third thing is find the specific function that you need say for example um you know you want to you want to send a message or you want to pause Spotify and right now na10 has it but if you want you know you have to make sure that the function or the thing you're trying to do is supported by the API and then you just create that request in n10 and we're going to look at uh examples and screenshots for each of these steps and then we're going to look at an example uh that uh adds uh functions to an for a node that already exists and for a function for to talk to an application that does not have a native node for an right um so uh the first so like I mentioned before the easiest way to find out if there is an API is you can check the website you can read the application documentation and normally you will find

### [5:00](https://www.youtube.com/watch?v=Lfd23yFKyUo&t=300s) Segment 2 (05:00 - 10:00)

uh things about the API under the developer section or uh you know the integration section uh and often more often than not you can just you know do a Google search for the name of whatever you want to connect and just add API or API documentation and you know Google should just find it for you um here is uh a quick video of me finding uh the API for an appli called outline uh it's a Wiki app that I tend to use and this is something that you will see in other examples as well so you can see that I was able to go to the website and find the developer section and I've also done a Google search outline wiy API and the first result takes me directly to you know all of the documentation about the API so from there I can start to read it and you know find the functions that I need right um so but before we do that we need to make sure we have access to the API and um there's two ways right now in n0 HTTP request node that you can do this so if you are accessing the API of an application for which na10 already has a node then there is an option that says used predefined uh credentials and you can just select that and pick from your existing credentials an example of this that you will see later in this uh presentation is mat you can just uh use the those credentials to make a request to that API um if you're trying to connect to an app that does not have a node then you have to find the authentication information in the API documentation and then replicate that setup in Anon so here I have a screen recording of me again with outline Wiki creating uh finding the authentication and you know demonstrating how to create uh the authentication in the HTTP request node um so you can see I'm highlighting the relevant information as you can go it says that you it needs header authentication using a bearer token and that you can create that key in the account settings uh so I'm going to go into the wiki app go into the preferences API tokens and I'm going to create a token I'm going to give it a name and I've created that I'm going to copy that token and then go into na10 and create a new HTTP request node and under authentication select generate credential type header authentication because that's what we saw in the documentation and I'm going to give it a friendly name can authorization and you can um see that you need it to be authorization and then it's I'm typing in here Bearer space and I'm pasting the API key that I copied from the application and that's it right and you can follow similar steps for any application that you want to connect with an1 just select the appropriate authentication method here it was head o select the appropriate one and then just take the information from the app and you know put it in um and then the next step of course is then to go through the API documentation and find out the function that you want it to do so in the example I'm showing today since I'm demonstrating with a Wiki application I'm going to search for a document with keywords right and I'm looking for in my Wiki a branding guideline that was written a while ago and so this is the API documentation for uh searching uh all of the documents in my Wiki and these are all the options that you can use and you can see at the end of the screenshot that it's a post request uh and the endpoint is documents. search the URL that you make the HTTP request to for that specific function and you'll see me do that um in this u in this example here uh so in this workflow I'm implementing not one but two requests uh from for the same app one which searches for all results and then uh retrieves the first search result from the wiki right so let's take a look so you can see that it's uh it's should say documents. search and there's

### [10:00](https://www.youtube.com/watch?v=Lfd23yFKyUo&t=600s) Segment 3 (10:00 - 15:00)

the endpoint URL I'm using and I'm selecting the API credential I've already created and I'm making sure that I'm specifying a query parameter that's as you know mentioned in the API documentation and I'm searching for the word brand guideline and you can see that I'm getting search results and then I'm using another API call to the same API to retrieve that document and I've taken the document ID from my previous request and passed it on to this one so this is a good example of when you can also connect multiple HTTP request nodes to accomplish you know a series of things say there is an app that you really need multiple functions with that no node is available for this is something that you can do right um so this is an example of how to utilize an HTTP request node uh for an application that does not have a node at all uh it is rather straightforward and simple as you can see and I hope that you all give it a try uh the next example is going to be um for using um HTTP request to perform a function uh for which that's not available in the native n node so like I have talked about it earlier so here what I'm doing is uh I have a slack workspace uh that we use and I have we also have a mattermost chat application that we talk on but uh sometimes you know when we when say I take a lunch break I update my slack status to say that I'm away but uh I may not do so in the other apparate and it can be quite a hassle and anat does have a Matos node but it does not support the function to update your uh status right so this is a workflow that will uh copy that will mirror my slack status uh into mattermost every five minutes and so if I'm away for lunch in the next five minutes this workflow should run and automatically let people know that um I'm you know aware right so let's take a look at that so you can see the workflow already here I'm showing here the API request let me just pause it so um this is uh this URL is the mattermost um API endpoint for setting uh for set setting a custom status right and if you go down you can see that I am passing an emoji and a text so which is you know the icon and the message that is displayed in your status and the other one is present so that's basically the little green circle that says you're online or offline interestingly in slack and matamos these are two separate things and you can see here that um I'm demonstrating here that the statuses are you know different and online on either application and I'm going to go ahead now in slack update my status to say I'm going to rest and change my icon to a bed I'm going to save that and then I'm going to change my little online green thing to you know say that I'm away and then when I run this workflow it should get that status and presence from slack and then replicate on mattermost and if you see that it says the same thing and says that I'm away right so this is an example of using um U the HTTP request node to just extend an existing nodes function and one key thing that I want to demonstrate here that I may not have pointed out before is if you can see this HTTP request node that I'm using for Matos as opposed to the first example here I am using authentication as the predefined credential type so I'm not manually creating any authentication but rather I'm using what if the authentication and the credential that I have already saved for the built-in Matos node so that's one key thing that I want to point out here I have not um I have not here you know shown uh demonstrated you know pulling the M most API documentation or

### [15:00](https://www.youtube.com/watch?v=Lfd23yFKyUo&t=900s) Segment 4 (15:00 - 20:00)

you know finding that endpoint but it is very straightforward for most apis that are documented and you can just run a similar search and then try a similar workflow out for yourself right and for the last example this is more of a um an edge case so to speak um done one comment we're a little bit out of time so if you could speed this part up a little bit that would be great yes of course um so this is about dealing with pagination and rate limiting um so sometimes apis don't return you know all the possible data and they return it in smaller chunks uh because it would be impossible to return a huge data set and the way they handle this is by returning chunks of data and this is called pagination and this video is an example of uh of a workflow that pulls you know posts under from the N1 Community Forum that says you know the tag cloud and um and just you know displays them it dis it iterates through them different pages and pulls those uh posts out and there's a time out for 5 seconds uh to prevent the community Forum itself from blocking us uh with something that's called rate limiting uh but let's just uh Jump Right In here and you can see that there's the request that's created and I the query parameter is Page and you can specify the item that you need to iterate upon can you maximize the video first oh yes sorry um I think sorry yep here we go and yeah so I'm just going to skip through the execution part cuz that's just a lot of waiting and Skip here through the output and you can see that you know there it has fetched six different times from the API which is why it says there are six items and it has fetched you know uh different U users and posts that have been made under the cloud tag on the community Forum so this is an example of you know something that's a little more uh Advanced or complicated uh like an edge case that you may have to deal with which is Page nation and rate limiting but I think I'm running out of time now so let's end you can find me as SM Aman on the community forum and feel free to ask me any questions uh but do we have any time for question yes we do thanks Mudan this was really great examples to I like the synchronization of the the statuses there um we have two questions I think you you kind of touched on the second one already the first one um hang on let me just go back to sharing my screen yes first one you need me to stop okay oh no that's fine first question is can we use HTTP node with apis that uses o and I think it's kind of related to the second one right the difference between generic and predefined authentication yes um yes you can use HTTP node with uh apis that use o and if you use doing it for a node that already uses o you can do the predefined Authentication and if you are not then you can go into generic and then you can select oath and oath 2 as a type and then you can put in your client ID client secret and you have to of course configure n10 with n1's call back URL that is provided in the other site and you can totally do that and connect your account that's possible and you can find the documentation uh on the n0 website it's quite uh clear um the next question I'm seeing is what is the difference between generic and predefined authentication uh predefined authentication is a way for you to reuse uh saved credentials from existing nodes so in my example I had a Matos node but I also used the HTTP request node to make a request to MOS API but instead of configuring a separate credential again just for that HTTP request I just used those same credentials that was saved for the matter most note that's predefined authentication generic authentication is when you configure something uh that for a node that's not already there and you might have to do it for every single HTTP request node and there is not much reusability um any other questions no I think that's it Louis any last minute editions no new ones some conversations in the threads there in the chat but I think those were the m was okay all right this was a great

### [20:00](https://www.youtube.com/watch?v=Lfd23yFKyUo&t=1200s) Segment 5 (20:00 - 20:00)

introduction thanks for this overview and I'm sure we can reuse this video for a lot of people afterwards as well

---
*Источник: https://ekstraktznaniy.ru/video/15670*