Hey there stranger!
Sign up to get access.
Create Your Own API by Deploying a Web App
About this Tutorial
0:16 Where we take an email in and we save it to a sheet. We also have embedded a headline in a website where we take data from a Google Sheet and get it into a website.
0:29 Same with embed a number in a Google Sheet. So we have these functions here. In this video in particular, what we're going to do is we're going to create our own API.
0:39 We're going to do a do get, which is the ultimate thing that we end up using. It's a built in function inside of Google Apps Script that all we have to do is literally do this five letters, do get, and then we can create our own API here.
0:56 So let me show you a little bit of what I'm talking about where we're going to create an API where there is a URL.
1:05 A completely open URL that we can send data to and we'll get back some data. We're going to build that.
1:11 And I think what's going to happen, and I hope, that by doing this you'll see the inner workings of an API so that you will be better to, you will.
1:21 It will be better and easier for you to understand how to access APIs once we know what's going on inside.
1:27 So let me show you this one, which is from Google itself. It's a URL called s2.googleusercontent.com slash s2. And what we're doing is we're sending a domain name.
1:41 We can send any domain name. We're going to do Google.com here. And it will come back with an image, an icon.
1:50 So we have this literally it's just image. Change. A formula that we're using right now, but the inside of it is this URL that exists and we just need to figure out what the domain is, right?
2:02 We're sending the domain name and we're getting back the image. We can do this as well with Airbnb.com. We can do this.
2:09 With think CNN.com. Right? Any website that has a favicon, we're gonna go out, grab it and we're using this URL.
2:21 We're not going and scraping that website. We're not doing much of anything. Except accessing this URL that exists. And that's what we're gonna build today.
2:30 I'm gonna need a few things. One is we're gonna have to go to extensions app script. First step. We already have it open here.
2:37 And the whenever you open this as you've seen previous in previous videos. Is a watch those other previous videos. I just mentioned embed a number in a website, text, email sheets, or any coding.
2:48 We're always gonna start with function my function. But in this case, we're gonna change this to do get. We're going to add in a little something here.
2:56 We need URL, which is going to be a very variable. It says we're gonna grab a URL when we when we ultimately deploy this web app, which you will see later in this email in this not in this email in this video.
3:10 We're gonna do it very similar to this email to sheets because this is. A basically web app we've deployed and it is essentially API, but we're gonna do do get so I'm actually going to copy all of this.
3:25 We're gonna edit it a little bit. Yeah, we're gonna get. All of that and we're gonna get edit. So first off, we do need this variable params because we need the parameters of the URL.
3:38 We do not need email. This is going to be something we ourselves are going to set up right now. What this means is this params.email if you see in this in this URL here, after the favicon there's a question mark.
3:59 And then there's domain equals and we're just putting in the domain that we want. That name the text domain, that's a parameter.
4:09 So ultimately, what we want to get is this URL is going to come with, have a URL and then a question mark and then some parameters that we set up.
4:18 We are going to create, create this API from the inside. So instead of email we want to create a, let's do just a little text just a little text transformation.
4:30 Very simple text transformation. We're going to take any word that comes in. We're going to return a domain name, which would just add .com to it.
4:38 Super simple as an example of what we can do here. So we're going to get word. That's it. We're going to have variable word here and that word we don't need to do anything with it.
4:54 We don't need to log this at all. We're not, we're going to make this super simple. We're going to return and we're going to create this output.
5:06 We're going to actually call it. This output and create variable output equals word plus dot com. That's it. Now, this is super simple to show you the construct of this.
5:21 In this particular video, we may do more complicated APIs, but in this case, we're just at taking the word that comes in in our parameter, and we're getting pushback.com.
5:35 And if not, if there's some error, we're going to try this? First, we're going to, if we get an error, we're going to catch that error and then we're going to return the error.
5:44 So how we actually deploy this is Command S or hit the save project up here. Wait a moment for it to save.
5:52 Now we have our API completely done, if you could imagine that. The next thing we're going to have to do is deploy new deployment and in this case we do need to do a couple of simple things.
6:03 We're going to create a web app, that is one thing. We don't need a description but we're going to do add.com.
6:11 We're going to execute as me. That's going to execute as me. But then who has access as anyone? That is important to do.
6:18 If you want to keep this more secure, there are other options here. But we're going to make this a completely open API.
6:26 So we're going to click deploy. In our construct of an API, we need to tell people what parameters to use.
6:34 And once this updates, it does take a moment or two, the very first time you do it. When you manage deployments or you update this deployment, which we will do soon.
6:45 You will see that it takes much less time. So we need this URL and I'm going to open an incognito window.
6:52 I'm going to paste this URL here that we got. And at the end, I'm going to do question mark, word.
7:01 And we're going to say Google. We're going to hit enter and see what happens. And what we get here is literally the response, Google.com.
7:10 So it has done exactly what we asked it to do, right? So let's look at this again. We have asked it here.
7:17 We're entering the URL which is that web app URL, we're adding the question mark and parameter word which we've defined right here.
7:24 And when we create this API we can save it ourselves, we can use this ourselves or if we wanted to publish this API publicly.
7:32 We just need to tell people how to use this which is have this URL, this long URL here, at the end put a question mark and put word equals and then put your word and we'll add the .com.
7:45 So if we want to edit this, say we don't want .com, we want to edit this. We're actually going to close that.
7:52 And we're like, actually we want .co. So I'm going to call this the .co API and we've saved it and now we deploy new deployment again.
8:03 You'll see here we can add a description. A new description. We don't need to, but we can say now it's .co if we want to.
8:10 All of these settings are the same and we just hit deploy again. That's it. This will update that web app URL, but the thing is we need to get this new URL.
8:19 It's always going to be a new URL. So now let's go to our incognito window, add question mark, word equals, and we'll say CNN.
8:29 And what do we get here? CNN.co. That's it. We have created a brand new, your own API. We've created an API, we can edit that API, we can add some text, text transformations, we can do some math if we want, and it'll export ex- yeah, it'll return to anyone using this URL and in the way that we
8:52 have de- Thank you.
Add Icons To Your Sheets With a Domain Name
Create Your Own API by Deploying a Web App
OpenSea Data Inside Sheets
Tag Emails From A List of Members in Google Sheets
Spreadsheet Automation 101 Lesson 4: Access APIs Introduction
How to Validate Email Addresses
Spreadsheet Automation 101 Lesson 4: UrlFetchApp
Spreadsheet Automation 101 Lesson 4: OmdbAPI get ApiKey, get Data in URL
Spreadsheet Automation 101 Lesson 4: OmdbAPI Parameter Picker
Spreadsheet Automation 101 Lesson 4: OmdbAPI get data in Apps Script
Spreadsheet Automation 101 Lesson 4: JSON (beautifier) and OmdbAPI parameters
Quickstart Tutorial OpenAI API in Google Sheets
Shaman: AI Blog Writer
ChatGPT Clone in Google Sheets Part 1
ChatGPT Clone in Google Sheets Part 2
How To Set Up Stripe Webhook to Google Sheets with Google Script
Create Instant QR Codes