Hi everyone.
Welcome back.
In this lesson we are going to talk about APIs.
So the key concept you need to understand before building powerful automations in N810.
So we'll go over what an API is and how it works.
And the main components of an API request and response.
This will be a little bit more technical, but once you understand this you'll be able to connect almost
any app or service to N810 and automate tasks like a pro.
Now what is an API?
So API stands for Application Programming Interface.
That sounds complicated, but it's really just a way for two applications to talk to each other.
So it's like a bridge between two applications.
Imagine you are at a restaurant and you sit at your table and call the waiter.
So you give the waiter your order to your request.
And the waiter takes your requests to the kitchen.
So to the application at the kitchen prepares your meal and give it to the waiter, and the waiter brings
the food back to your table.
So response back to you.
In this analogy, you, the customer, are the client because you make the request.
The waiter is the API because it delivers requests and returns response, and the kitchen is the application
because it processes the request.
So APIs allow apps to send and receive information automatically, just like a waiter helps you get
food from the kitchen without needing to cook it yourself.
And instead of manually entering data APIs, let software to do the work for you.
Now.
Why do we need APIs?
So APIs simplify complex tasks by handling communication between different applications.
Just like a waiter in a restaurant makes ordering food easier.
So let's extend the restaurant example.
So imagine you are sitting at a restaurant and want to order food.
And instead of going into the kitchen yourself, you simply tell the waiter your order.
So the waiter takes your request to the kitchen where the food is prepared, and then the waiter delivers
the meat back to you.
And without API, you would need to go to the kitchen yourself and cook the meal for yourself.
So without APIs, automation wouldn't exist.
If APIs didn't exist, applications wouldn't be able to talk to each other And you would have to manually
move data between services.
So, for example, instead of automatically updating your Google Sheet when a new sale is made, you
would have to login into Google Sheets, copy and paste the new sale information, check for errors,
and manually update your database.
So that's very slow and repetitive process.
Now, thanks to API's, N810 can connect and automate different apps.
So thanks to Google Sheets API and your automation can automatically add new rows.
And when customer fills out a form or by using email API, your automation can automatically send an
welcome email when someone signs up on your website, or when you integrate calendar into your automations
and make API calls to calendar.
It allows automatically schedule meetings when a client books an appointment with you.
So APIs save a lot of time without you having to copy and paste data manually.
But how does an API work?
So every app you want to connect to should have an API documentation that tells you what services it
offers, what information you need to send, and how to structure your requests.
So think of it like a restaurant menu.
It tells you what's available and how to order it.
So when using an API, two things happen.
You send a request asking for data or performing an action, and the application responds, sending
back the request, the requested data or confirming the action.
Key API terms to know.
So before we dive into API requests, let's quickly define three important terms you will come across.
So API endpoints this is the specific web address.
So URL where the where the request is sent.
So think of it as the restaurant's kitchen address in our analogy.
API call.
This is the actual request sent to the API.
So just like giving an order to a waiter.
And HTTP request.
So this is the method used to send the API call over the internet like get post or delete methods.
So now let's break down an API request into four key parts.
Every API request has four main parts.
URL the unique web address where the request is sent.
Method what action you want to perform.
Get or post etc..
Get and post are the main two methods.
You also have headers so extra information like authentic authentication keys and body.
So the data you're sending it's only relevant for the post requests.
So let's go through them.
So method are the actions you want to do.
So the method tells the API what action you want to take.
So imagine you are ordering food and get.
It's like asking for the money.
So retrieve information.
Post is like placing a new order.
So send new data.
Delete is like canceling an order.
So remove data and put.
And patch is like changing an order to like, update data.
So for example, if you want to
It uses get method, but if you want to add a new row to the sheet, it uses post method.
Now that we understand the four parts of an API request, let's see how this works inside an item using
the HTTP request node.
Now let's say we want to use the HTTP request node to send API request.
So let's search for HTTP request.
Now the HTTP request node in N810 allows you to send API request to different services, just like a
messenger delivering a request and bringing back responses.
So for example, let's say we want to retrieve data from a Google sheet using its API.
Instead of manually opening Google Sheets and searching for data.
and copying it yourself, and then can send an API request automatically and get the data for you.
So in this example, we need to enter the Google Sheets api url inside the HTTP request node.
So in this field and this tells Google Sheets where to fetch the data from.
We also need to specify the method.
So the action.
So the method tells the API what action to take.
So think of it like ordering food at a restaurant.
So get is like asking for the money.
And post is like play.
Usually you just use those two methods.
And since we want to retrieve data from Google Sheets, we select get method.
If you wanted to add a new row, you would use A post method.
Now headers specify extra info.
Some APIs require authentication, just like logging into an app.
In N810, we add an authorization header with an API key or token to securely connect to Google Sheets
and also body, so only for a Post requests.
If you wanted to send new data instead of retrieving it, you would enter the data inside the body section.
For example, if you wanted to add a new row, we would send the values inside the request body.
Now, once we have set up everything up, we execute the HTTP request node and N810 will send the API
request to Google Sheets, receive the response from the API, and then pass the data to the next step
in the workflow.
So this allows any attempt to automate API calls without any manual work.
So now let's talk about what happens after N810 sends an API request and how APIs respond with data.
This is just to visually present how this works, but we will use the HTTP request node in a real project
later in the course.
Now that we understand how to send API requests, let's talk about what happens when we get a response
from the API.
So every time we send a request, the API sends back a status code.
So a three digit number that tells us whether our request was successful or if something went wrong.
So how APIs respond to your requests and what those responses actually mean.
So when you send an API request, you always get a response back.
And this response contains three key parts status code.
So this tells us if the request was successful or if there was a problem.
For example, 200 means everything is fine, while 404 means the requested data wasn't found.
Headers.
This contains extra details like what type of content is being sent or how long the data is valid.
And body.
This is the actual data you requested.
So if you are fetching Google Sheets data, this is where the spreadsheet content would appear.
So now let's break down status codes because they help us understand what's happening when we interact
with an API.
So API responses fall into three main categories and each starts with a different number.
So when you see two followed by any number, it means that everything worked as expected.
So you got the data or completed the action successfully.
So for example, 200 means that the request was successful and the API returns the data you asked for.
For followed by any number means client error.
So there is an issue with your request, meaning you need to fix something before trying again.
For example, 401 means unauthorized so you are not allowed to access this data.
Maybe you forgot to add your API key, or 404 is not found, so the URL is incorrect or the requested
data does not exist.
And five followed by any number means server error.
The problem is on the API side, so it's not your fault and you may need to try again later.
For example, 500 means internal server error.
So something went wrong on the server and it's not your fault.
Now, why APIs need authentication?
In other words, security measures.
So APIs often require authentication to protect data from unauthorized access.
So imagine if anyone could send a request to update your Google Sheets.
Your data could be changed or deleted by anyone.
And that's why most APIs require some form of authentication, like an API key or OAuth token before
allowing access.
So for example, if you want to update a Google Sheet, your request needs an authorization header like
this one.
So basically you need to provide your API keys because without proper authentication, the API will
reject the request with a 401 One unauthorized error, which means you don't have permission in any
ten.
When using the HTTP request node, you can securely enter authentication details inside the headers
or use of credentials for services like Google, slack, stripe, and so on.
So this ensures your API calls are secure and authorized.
Next, troubleshooting API errors in N810.
So let's talk about common API errors and how to fix them in N810.
When you send an API request and something goes wrong, you don't need to panic because most issues
are easy to troubleshoot.
Here are the most common problems and how to fix them.
So the most common one is missing API key.
So if an API requires authentication and you forgot to include your API key, it will reject your request
with have a four with a 401 unauthorized error.
So to fix a 401 unauthorized error, you need to go to the HTTP request node.
And under headers, you need to make sure that you added the correct authorization key.
But if you are using OAuth authentication, you need to make sure you are logged in into the correct
account.
The second common API error is wrong api url.
It usually means the URL is incorrect.
So to fix it, you need to check your API URL to make sure that there are no any typos.
Some APIs require extra details in the URL, like an ID for a Google sheet or a specific resource.
Earth.
Compare your URL with the API documentation to make sure you are using the correct format.
The next one incorrect HTTP method.
So APIs expect different methods depending on what you want to do.
If you use the wrong one, the request might fail.
So to fix it, always use get method.
If you are trying to retrieve data.
And always use post method if you are sending new data.
And the last one invalid request body.
So for 100 request status if you are using a Post or Put request, most APIs expect data in JSON format
for Post and Put requests.
So for example, if it's missing or incorrectly formatted, you will get a 400 bad request error.
So make sure your data is in JSON format, which looks like this.
So key and value.
You can also double check the API documentation to see what data is required.
I will cover JSON format in a later lesson, so don't worry if it's new to you.
For now, just know that many APIs expect data to be formatted in this way.
So JSON format and it then provides helpful error messages inside the execution log.
So to easily find out what causes the issue.
You can go to executions.
Click on the HTTP request node in your workflow.
And you will see what went wrong.
So in that case you didn't provide the URL.
So the error message will usually tell you exactly what needs to be fixed.
All right.
Great.
Let's quickly recap and go over what we covered in this lesson.
So APIs allow apps to talk to each other, just like a waiter in a restaurant takes you order to the
kitchen and brings back your food.
When sending an API request you need for meetings, a URL where the request goes, a method, what action
to take like get or post headers.
So extra info like authentication and finally a body to send the data.
After sending a request.
The API response with a status code.
So 200 means success 404 means not found.
A headers Here's to extra details about the response.
And body to the actual data you requested.
We also covered authentication, so most APIs need an API key or off login to keep data secure.
And if something goes wrong, check the execution log in N810.
It tells you exactly what to fix.
In the next lesson, we'll cover webhooks and how they let apps send data to N810 in real time without
needing to constantly check for updates.
Because when you use an API call, the HTTP request node has to continuously send requests to check
for new data, like refreshing a Google Sheet every few minutes to see if anything changed.
So this happens automatically, but it's not the most efficient way.
Thank you for your attention and see you in the next one.