WEBVTT

00:00.360 --> 00:00.960
Hi everyone.

00:00.960 --> 00:01.960
Welcome back.

00:02.000 --> 00:05.040
In this lesson we are going to talk about APIs.

00:06.000 --> 00:11.480
So the key concept you need to understand before building powerful automations in N810.

00:12.240 --> 00:15.840
So we'll go over what an API is and how it works.

00:16.200 --> 00:19.400
And the main components of an API request and response.

00:20.280 --> 00:26.520
This will be a little bit more technical, but once you understand this you'll be able to connect almost

00:26.520 --> 00:30.720
any app or service to N810 and automate tasks like a pro.

00:33.960 --> 00:35.320
Now what is an API?

00:35.720 --> 00:38.920
So API stands for Application Programming Interface.

00:39.400 --> 00:45.000
That sounds complicated, but it's really just a way for two applications to talk to each other.

00:45.440 --> 00:47.560
So it's like a bridge between two applications.

00:49.240 --> 00:54.160
Imagine you are at a restaurant and you sit at your table and call the waiter.

00:55.680 --> 00:59.720
So you give the waiter your order to your request.

01:00.200 --> 01:03.040
And the waiter takes your requests to the kitchen.

01:03.760 --> 01:12.440
So to the application at the kitchen prepares your meal and give it to the waiter, and the waiter brings

01:12.440 --> 01:13.880
the food back to your table.

01:14.680 --> 01:17.320
So response back to you.

01:19.520 --> 01:27.520
In this analogy, you, the customer, are the client because you make the request.

01:28.160 --> 01:37.560
The waiter is the API because it delivers requests and returns response, and the kitchen is the application

01:38.000 --> 01:40.000
because it processes the request.

01:40.360 --> 01:48.200
So APIs allow apps to send and receive information automatically, just like a waiter helps you get

01:48.200 --> 01:51.800
food from the kitchen without needing to cook it yourself.

01:52.280 --> 01:57.840
And instead of manually entering data APIs, let software to do the work for you.

02:00.080 --> 02:00.560
Now.

02:02.800 --> 02:04.160
Why do we need APIs?

02:04.280 --> 02:11.680
So APIs simplify complex tasks by handling communication between different applications.

02:12.000 --> 02:15.560
Just like a waiter in a restaurant makes ordering food easier.

02:16.680 --> 02:19.840
So let's extend the restaurant example.

02:20.920 --> 02:24.760
So imagine you are sitting at a restaurant and want to order food.

02:25.080 --> 02:30.720
And instead of going into the kitchen yourself, you simply tell the waiter your order.

02:30.880 --> 02:36.520
So the waiter takes your request to the kitchen where the food is prepared, and then the waiter delivers

02:36.520 --> 02:37.560
the meat back to you.

02:38.960 --> 02:45.320
And without API, you would need to go to the kitchen yourself and cook the meal for yourself.

02:48.120 --> 02:52.280
So without APIs, automation wouldn't exist.

02:52.760 --> 03:00.090
If APIs didn't exist, applications wouldn't be able to talk to each other And you would have to manually

03:00.130 --> 03:02.330
move data between services.

03:03.850 --> 03:11.290
So, for example, instead of automatically updating your Google Sheet when a new sale is made, you

03:11.330 --> 03:17.970
would have to login into Google Sheets, copy and paste the new sale information, check for errors,

03:18.090 --> 03:19.730
and manually update your database.

03:20.330 --> 03:22.810
So that's very slow and repetitive process.

03:24.610 --> 03:28.850
Now, thanks to API's, N810 can connect and automate different apps.

03:29.210 --> 03:35.090
So thanks to Google Sheets API and your automation can automatically add new rows.

03:35.130 --> 03:44.810
And when customer fills out a form or by using email API, your automation can automatically send an

03:44.810 --> 03:51.610
welcome email when someone signs up on your website, or when you integrate calendar into your automations

03:51.730 --> 03:53.730
and make API calls to calendar.

03:54.130 --> 03:59.490
It allows automatically schedule meetings when a client books an appointment with you.

03:59.930 --> 04:05.330
So APIs save a lot of time without you having to copy and paste data manually.

04:10.250 --> 04:11.970
But how does an API work?

04:12.570 --> 04:19.610
So every app you want to connect to should have an API documentation that tells you what services it

04:19.610 --> 04:24.210
offers, what information you need to send, and how to structure your requests.

04:24.850 --> 04:28.130
So think of it like a restaurant menu.

04:28.290 --> 04:31.410
It tells you what's available and how to order it.

04:32.090 --> 04:34.690
So when using an API, two things happen.

04:35.450 --> 04:43.610
You send a request asking for data or performing an action, and the application responds, sending

04:43.610 --> 04:47.970
back the request, the requested data or confirming the action.

04:52.330 --> 04:53.730
Key API terms to know.

04:54.010 --> 05:00.330
So before we dive into API requests, let's quickly define three important terms you will come across.

05:01.490 --> 05:04.730
So API endpoints this is the specific web address.

05:04.730 --> 05:08.450
So URL where the where the request is sent.

05:09.090 --> 05:13.850
So think of it as the restaurant's kitchen address in our analogy.

05:15.090 --> 05:16.050
API call.

05:16.050 --> 05:18.610
This is the actual request sent to the API.

05:18.970 --> 05:21.330
So just like giving an order to a waiter.

05:21.850 --> 05:23.610
And HTTP request.

05:24.050 --> 05:31.450
So this is the method used to send the API call over the internet like get post or delete methods.

05:32.210 --> 05:36.450
So now let's break down an API request into four key parts.

05:39.250 --> 05:42.610
Every API request has four main parts.

05:43.650 --> 05:47.650
URL the unique web address where the request is sent.

05:48.090 --> 05:51.770
Method what action you want to perform.

05:52.210 --> 05:54.050
Get or post etc..

05:55.730 --> 05:58.730
Get and post are the main two methods.

06:00.610 --> 06:08.850
You also have headers so extra information like authentic authentication keys and body.

06:09.250 --> 06:14.690
So the data you're sending it's only relevant for the post requests.

06:16.450 --> 06:17.490
So let's go through them.

06:21.770 --> 06:25.010
So method are the actions you want to do.

06:25.610 --> 06:30.530
So the method tells the API what action you want to take.

06:31.130 --> 06:34.890
So imagine you are ordering food and get.

06:36.010 --> 06:37.690
It's like asking for the money.

06:37.730 --> 06:39.210
So retrieve information.

06:39.850 --> 06:41.970
Post is like placing a new order.

06:42.210 --> 06:43.570
So send new data.

06:44.170 --> 06:46.610
Delete is like canceling an order.

06:46.770 --> 06:48.890
So remove data and put.

06:48.930 --> 06:52.730
And patch is like changing an order to like, update data.

06:53.250 --> 06:54.930
So for example, if you want to

06:58.170 --> 07:06.290
It uses get method, but if you want to add a new row to the sheet, it uses post method.

07:07.050 --> 07:14.290
Now that we understand the four parts of an API request, let's see how this works inside an item using

07:14.330 --> 07:15.850
the HTTP request node.

07:18.730 --> 07:24.290
Now let's say we want to use the HTTP request node to send API request.

07:24.930 --> 07:27.090
So let's search for HTTP request.

07:31.970 --> 07:40.170
Now the HTTP request node in N810 allows you to send API request to different services, just like a

07:40.170 --> 07:44.930
messenger delivering a request and bringing back responses.

07:45.410 --> 07:50.530
So for example, let's say we want to retrieve data from a Google sheet using its API.

07:50.930 --> 07:54.730
Instead of manually opening Google Sheets and searching for data.

07:56.060 --> 08:02.660
and copying it yourself, and then can send an API request automatically and get the data for you.

08:03.260 --> 08:11.340
So in this example, we need to enter the Google Sheets api url inside the HTTP request node.

08:11.860 --> 08:17.220
So in this field and this tells Google Sheets where to fetch the data from.

08:19.460 --> 08:21.420
We also need to specify the method.

08:21.820 --> 08:22.860
So the action.

08:23.580 --> 08:27.220
So the method tells the API what action to take.

08:27.820 --> 08:31.380
So think of it like ordering food at a restaurant.

08:32.540 --> 08:36.140
So get is like asking for the money.

08:36.780 --> 08:39.500
And post is like play.

08:39.980 --> 08:42.660
Usually you just use those two methods.

08:43.900 --> 08:48.660
And since we want to retrieve data from Google Sheets, we select get method.

08:49.460 --> 08:55.820
If you wanted to add a new row, you would use A post method.

08:57.980 --> 09:00.540
Now headers specify extra info.

09:00.980 --> 09:05.620
Some APIs require authentication, just like logging into an app.

09:06.540 --> 09:13.900
In N810, we add an authorization header with an API key or token to securely connect to Google Sheets

09:15.780 --> 09:19.740
and also body, so only for a Post requests.

09:19.980 --> 09:26.300
If you wanted to send new data instead of retrieving it, you would enter the data inside the body section.

09:26.780 --> 09:33.380
For example, if you wanted to add a new row, we would send the values inside the request body.

09:37.460 --> 09:46.140
Now, once we have set up everything up, we execute the HTTP request node and N810 will send the API

09:46.140 --> 09:51.740
request to Google Sheets, receive the response from the API, and then pass the data to the next step

09:51.740 --> 09:52.580
in the workflow.

09:53.420 --> 09:58.460
So this allows any attempt to automate API calls without any manual work.

09:58.980 --> 10:06.300
So now let's talk about what happens after N810 sends an API request and how APIs respond with data.

10:07.020 --> 10:15.260
This is just to visually present how this works, but we will use the HTTP request node in a real project

10:15.260 --> 10:16.340
later in the course.

10:17.060 --> 10:23.900
Now that we understand how to send API requests, let's talk about what happens when we get a response

10:23.900 --> 10:24.900
from the API.

10:25.140 --> 10:29.740
So every time we send a request, the API sends back a status code.

10:30.340 --> 10:37.180
So a three digit number that tells us whether our request was successful or if something went wrong.

10:37.540 --> 10:42.540
So how APIs respond to your requests and what those responses actually mean.

10:44.100 --> 10:47.940
So when you send an API request, you always get a response back.

10:48.300 --> 10:51.940
And this response contains three key parts status code.

10:52.140 --> 10:57.220
So this tells us if the request was successful or if there was a problem.

10:57.700 --> 11:05.780
For example, 200 means everything is fine, while 404 means the requested data wasn't found.

11:06.940 --> 11:07.540
Headers.

11:07.940 --> 11:14.100
This contains extra details like what type of content is being sent or how long the data is valid.

11:14.780 --> 11:15.500
And body.

11:15.500 --> 11:17.540
This is the actual data you requested.

11:17.700 --> 11:22.860
So if you are fetching Google Sheets data, this is where the spreadsheet content would appear.

11:23.980 --> 11:31.060
So now let's break down status codes because they help us understand what's happening when we interact

11:31.060 --> 11:32.020
with an API.

11:33.060 --> 11:39.100
So API responses fall into three main categories and each starts with a different number.

11:41.860 --> 11:48.980
So when you see two followed by any number, it means that everything worked as expected.

11:48.980 --> 11:52.300
So you got the data or completed the action successfully.

11:55.060 --> 12:01.420
So for example, 200 means that the request was successful and the API returns the data you asked for.

12:02.060 --> 12:06.140
For followed by any number means client error.

12:06.700 --> 12:11.380
So there is an issue with your request, meaning you need to fix something before trying again.

12:12.620 --> 12:20.020
For example, 401 means unauthorized so you are not allowed to access this data.

12:20.060 --> 12:29.540
Maybe you forgot to add your API key, or 404 is not found, so the URL is incorrect or the requested

12:29.540 --> 12:31.500
data does not exist.

12:34.380 --> 12:37.900
And five followed by any number means server error.

12:38.100 --> 12:44.540
The problem is on the API side, so it's not your fault and you may need to try again later.

12:45.380 --> 12:48.820
For example, 500 means internal server error.

12:49.100 --> 12:52.670
So something went wrong on the server and it's not your fault.

12:56.310 --> 12:59.030
Now, why APIs need authentication?

13:00.670 --> 13:02.390
In other words, security measures.

13:03.590 --> 13:09.630
So APIs often require authentication to protect data from unauthorized access.

13:09.990 --> 13:14.470
So imagine if anyone could send a request to update your Google Sheets.

13:17.110 --> 13:19.630
Your data could be changed or deleted by anyone.

13:20.190 --> 13:29.870
And that's why most APIs require some form of authentication, like an API key or OAuth token before

13:29.910 --> 13:30.910
allowing access.

13:31.310 --> 13:37.390
So for example, if you want to update a Google Sheet, your request needs an authorization header like

13:37.390 --> 13:37.950
this one.

13:39.110 --> 13:46.950
So basically you need to provide your API keys because without proper authentication, the API will

13:46.950 --> 13:53.830
reject the request with a 401 One unauthorized error, which means you don't have permission in any

13:53.830 --> 13:54.150
ten.

13:54.190 --> 14:00.390
When using the HTTP request node, you can securely enter authentication details inside the headers

14:00.870 --> 14:07.750
or use of credentials for services like Google, slack, stripe, and so on.

14:08.070 --> 14:12.310
So this ensures your API calls are secure and authorized.

14:15.430 --> 14:18.350
Next, troubleshooting API errors in N810.

14:19.110 --> 14:23.110
So let's talk about common API errors and how to fix them in N810.

14:23.590 --> 14:30.430
When you send an API request and something goes wrong, you don't need to panic because most issues

14:30.430 --> 14:32.070
are easy to troubleshoot.

14:32.590 --> 14:35.750
Here are the most common problems and how to fix them.

14:37.430 --> 14:41.790
So the most common one is missing API key.

14:42.390 --> 14:48.510
So if an API requires authentication and you forgot to include your API key, it will reject your request

14:48.550 --> 14:55.070
with have a four with a 401 unauthorized error.

14:56.990 --> 15:04.110
So to fix a 401 unauthorized error, you need to go to the HTTP request node.

15:05.590 --> 15:13.190
And under headers, you need to make sure that you added the correct authorization key.

15:16.030 --> 15:23.630
But if you are using OAuth authentication, you need to make sure you are logged in into the correct

15:23.630 --> 15:24.190
account.

15:24.790 --> 15:29.310
The second common API error is wrong api url.

15:30.870 --> 15:33.390
It usually means the URL is incorrect.

15:33.910 --> 15:40.630
So to fix it, you need to check your API URL to make sure that there are no any typos.

15:41.350 --> 15:48.270
Some APIs require extra details in the URL, like an ID for a Google sheet or a specific resource.

15:48.270 --> 15:48.390
Earth.

15:48.910 --> 15:54.510
Compare your URL with the API documentation to make sure you are using the correct format.

15:55.510 --> 15:57.750
The next one incorrect HTTP method.

15:58.110 --> 16:02.350
So APIs expect different methods depending on what you want to do.

16:02.870 --> 16:06.590
If you use the wrong one, the request might fail.

16:07.550 --> 16:11.030
So to fix it, always use get method.

16:11.030 --> 16:12.750
If you are trying to retrieve data.

16:13.390 --> 16:16.670
And always use post method if you are sending new data.

16:18.710 --> 16:21.070
And the last one invalid request body.

16:22.190 --> 16:32.550
So for 100 request status if you are using a Post or Put request, most APIs expect data in JSON format

16:33.070 --> 16:34.670
for Post and Put requests.

16:34.950 --> 16:42.990
So for example, if it's missing or incorrectly formatted, you will get a 400 bad request error.

16:43.550 --> 16:47.670
So make sure your data is in JSON format, which looks like this.

16:49.030 --> 16:50.230
So key and value.

16:52.270 --> 16:56.710
You can also double check the API documentation to see what data is required.

16:57.630 --> 17:03.430
I will cover JSON format in a later lesson, so don't worry if it's new to you.

17:04.270 --> 17:09.910
For now, just know that many APIs expect data to be formatted in this way.

17:10.790 --> 17:17.910
So JSON format and it then provides helpful error messages inside the execution log.

17:18.870 --> 17:22.110
So to easily find out what causes the issue.

17:24.550 --> 17:26.990
You can go to executions.

17:30.390 --> 17:33.350
Click on the HTTP request node in your workflow.

17:35.710 --> 17:38.110
And you will see what went wrong.

17:38.550 --> 17:40.990
So in that case you didn't provide the URL.

17:42.710 --> 17:46.910
So the error message will usually tell you exactly what needs to be fixed.

17:49.640 --> 17:50.000
All right.

17:50.040 --> 17:50.520
Great.

17:50.520 --> 17:56.160
Let's quickly recap and go over what we covered in this lesson.

17:56.720 --> 18:04.920
So APIs allow apps to talk to each other, just like a waiter in a restaurant takes you order to the

18:04.920 --> 18:06.880
kitchen and brings back your food.

18:07.920 --> 18:18.680
When sending an API request you need for meetings, a URL where the request goes, a method, what action

18:18.680 --> 18:22.040
to take like get or post headers.

18:22.560 --> 18:29.960
So extra info like authentication and finally a body to send the data.

18:32.520 --> 18:34.320
After sending a request.

18:35.480 --> 18:38.400
The API response with a status code.

18:38.960 --> 18:43.840
So 200 means success 404 means not found.

18:45.400 --> 18:48.800
A headers Here's to extra details about the response.

18:51.200 --> 18:54.120
And body to the actual data you requested.

18:55.200 --> 19:03.480
We also covered authentication, so most APIs need an API key or off login to keep data secure.

19:04.920 --> 19:09.480
And if something goes wrong, check the execution log in N810.

19:09.520 --> 19:11.560
It tells you exactly what to fix.

19:12.560 --> 19:20.400
In the next lesson, we'll cover webhooks and how they let apps send data to N810 in real time without

19:21.000 --> 19:23.320
needing to constantly check for updates.

19:24.160 --> 19:32.040
Because when you use an API call, the HTTP request node has to continuously send requests to check

19:32.360 --> 19:38.320
for new data, like refreshing a Google Sheet every few minutes to see if anything changed.

19:39.120 --> 19:42.880
So this happens automatically, but it's not the most efficient way.

19:43.200 --> 19:46.280
Thank you for your attention and see you in the next one.
