Academy ↓
Hey there stranger!
Sign up to get access.
Use Random Quote API in Google Sheets
About this Tutorial
Sheet Resources
Video Transcript
0:12 One of my most favorite things right now is using RapidAPI so you're just going to have to sign up for a RapidAPI account, but it's free, don't worry.
0:23 And I got the code already written for you here, we're going to, but this is the crazy thing is that we didn't even really write this, I just edited it.
0:32 And I'm going to show you how to get the code and edit it and where to go. So we're going to create a new function here, so again, this function is get, get quote, I'm actually going to rename it get movie quote, and save it, and then go back and right here, we're going to say get.
0:48 Movie quote, and let's see, we got a name function here, a name error here, and here we got the movie quote.
0:56 So we want to get a normal quote now, and I'm going to show you all of the steps on how to do that and how to write this.
1:02 So we're going to create a new function up here. Function, get quote, put something in here, but we're not going to write it.
1:11 Alright, let's, I'm going to show you how to do this. So we got this random famous quotes here, it's an API on RapidAPI.com.
1:20 Sign up for an account and then the key here, I'm going to move my face right there, the key here is this button.
1:27 This will say subscribe. You're going to click that and it's free, zero dollars and you're going to subscribe. That is the key here.
1:35 So once you get to this random famous quotes subscribe to it, again it's free, you'll put in your details. And now, over here, on code snippets, we're going to use JavaScript and the fetch here.
1:50 Okay, this code is what we need. And you'll see in a hot second why. So again, just get your free random rapid API go to random famous quotes, this is by Andres Olvera, this is an API, And it's working at least now, so we're gonna go into our function get quote and inside of our brackets we're gonna
2:10 paste exactly what we got. It might stylistically be a little different we're just gonna do that. And here's the URL we're gonna go to, it gets our rapid API key already.
2:24 We're gonna go ahead this URL, and we're gonna edit this URL in a hot second. We're doing method post. What you can do, let's go back to our code snippets, is get over here on the left side, get endpoint.
2:53 There's a post endpoint and a get endpoint. Literally the only difference is this method. So we're gonna change this method to get.
3:02 And down here, instead of a wait fetch in Google Sheets, we need to use, we're gonna not say fetch, we're gonna say URL, capital U-R-L.
3:12 U-R-L fetch app dot fetch. And we're gonna get the same URL, same options, all this stays the same. But now when we get a result, we're gonna get, it says await response text.
3:23 What we're gonna do is response dot get content text. And put the parentheses there. And now instead of console dot log result, we're gonna delete that and do return result.
3:36 You'll see this is not complete yet but we wanna see what do we get out of this. So save it, and again this is just get quote.
3:45 What do we get? We get this big JSON. This is, you can sort of see it right here. Quote played against Sam as time goes by.
3:53 We get a whole bunch of stuff, okay? We don't want all that stuff. What we want is const. J all lowercase JSON equals JSON uppercase, parse, and we want to parse the result.
4:08 And now, our return is going to be JSON dot, and we're, actually we're going to do in bracket zero. And then another bracket and quote.
4:19 And now, if we hit save, our big JSON will probably change, there it goes, it changes to one exact quote.
4:29 But we don't want to have to just do this. We can actually edit this from ten to one, it's up here in the count, we're just gonna do one.
4:37 And our category, movies, what's that? Well in here, we'll have, should be in the about section somewhere, hmmm. It says current categories are famous and movies, right here.
4:53 So, what we're gonna try is instead of category movies, we're gonna do category famous. Command S. To save. Make sure this saves.
5:08 Yeah, it's saved. Done. And now, we have a random famous quote. So, we can actually rename this famous quote. And now, every time when we use this function, it'll give us a random famous quote.
5:24 So, we have a working thing here. We have, it absolutely works. I want to do one more thing to show you something cool that I think we can do is, let's say instead of just two different functions, get quote, and we can even name this famous quote or get movie quote, what if we wanted to use this exact
5:46 code but in, in the function, say famous or movie. Well, let's see. How we do that. I'm going to show you.
5:54 So we're going to say get quote, but in this one I'm going to say famous. And this one I'm going to say category.
6:01 So inside of here we'll add the category. And instead of category equals famous, we will do plus plus. Actually we need to do single quotes around that.
6:14 And category. So we'll fill in the category, famous or we know famous or movie, for this get quote. We'll save this.
6:23 We'll say. Change this to get famous quote. And now we want to say get. Actually we'll just quote equals get quote.
6:35 And inside we need to put in parentheses famous. Thanks for or do exactly the same thing but inside we do movies.
6:51 And there we go. Now we have a movie quote or a famous quote upon whatever text we put in here.
6:57 We will start getting errors I think if we let's see what happens if we don't put it see if we do it wrong fam.
7:04 Alright we're gonna get nothing. What we might do here is put some kind of if Thank you. Category is equal to famous or category is equal to movies.
7:27 You Was it movies or movie? Yeah movies. And if that's the case then we will do all of this stuff that we're doing.
7:38 If that is not the case meaning we neither put in famous or movies as the category. Have a good night. Have a Have night. Sorry.
7:47 We do else and we'll return hey need to put in famous or famous or movies. Peace. Okay so now what happens is if the category is not famous or not movies it will tell us hey need to put it in and here we go hey need to put in movies famous or movies right there boom we got that so now we can control
8:14 this a little bit more and if it if we can't control it with movie or quote movies or quotes it will tell us that as well so this is really cool I'm thankfully you watched this whole video and really hoping you can use some more rapid API if you do use rapid API for other APIs let me know I'm happy to
8:31 see other use cases
Courses
Add Icons To Your Sheets With a Domain Name
00:04:21
Convert Google Sheets into a REST API
Add Tasks to Google Tasks From Google Sheets
Build a Book Recommender with AI in Google Sheets
Build a License Key Generator and API in 20 Minutes
Create Your Own API by Deploying a Web App
Access Free API's with Google Sheets
Use Random Quote API in Google Sheets
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
Build Your Own Free Domain Availability Checker
Build a Job Status Checker API in 15 Minutes
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
00:22:10
Create Instant QR Codes
Access the Dictionary API to get Definitions for Words in Google Sheets