Add a Famous Quote API to Google Sheets - SIMPLE
In this video, learn how to integrate a Famous Quote API into Google Sheets using RapidAPI, allowing you to fetch random quotes effortlessly. Follow along as we create and customize functions to retrieve quotes from various categories.
In this video, we're going to get a random quote from a movie or from a random quote, any quote, and we're going to use an API in this video. I'm going to show you how to do it, how, and it couldn't be easier. 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. Um, and I got the code already written for you here. But, this is the crazy thing, is that we didn't even really write this, I just edited it, 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 Use Random Quote API in Google Sheets Use Random Quote API in Google Sheets Quickly Build a Daily Random Motivational Quote Website
go back, and right here, We're going to say getMovieQuote, and let's see, we've got a name function here, a name error here, and here we've got the movie quote. 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. So, we're going to create a new function up here called function getQuote. Put something in here, but we're not going to write it. All right, let's, I'm going to show you how to, how to do this. So we got this random famous quotes here. It's an API on rapid API. com. You can search for it, sign up for an account. And then the key here, I'm going to move my face right there. Key here is this button. This will say, uh, subscribe. You're going to click that and it's free. Use Random Quote API in Google Sheets Use Random Quote API in Google Sheets Quickly Build a Daily Random Motivational Quote Website
Zero dollars and you're going to subscribe. That is the key here. So once you get to this random famous quotes, um, 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. Okay, this code is what we need. And you'll see in a hot second why. Um, so again, just get your free, random, rapid API. Um, go to random famous quotes. This is by Andres Olvera. This is an API and it's working at least now. So we're going to go into our function , get quote, and inside of our brackets, we're going to paste exactly what we got. Uh, it might stylistically be a little different. Um, we're just gonna do that. Use Random Quote API in Google Sheets Use Random Quote API in Google Sheets Quickly Build a Daily Random Motivational Quote Website
And here's the URL we're going to go to. It gets our rapid. API key already for us. Super cool. Um, we're going to change some of this try stuff down here. We don't actually necessarily need try, but I like that it is here as well. I like it. Okay. Um, right now what we're doing is we're going to get this URL and we're going to 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. There's a post end point and a get end point. And literally the only difference is this method. So we're going to change this method to get. And down here, instead of a weight fetch in Google sheets, we need Quickstart Tutorial OpenAI API in Google Sheets GPT in SHEETS Convert Google Sheets into a REST API Automatic Screenshot in Google Sheets
to use, and it Nazi u uh, fetch. We're gonna say URL, capital URL fetch app 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 AWAI response text. What we're gonna do is response dot get content text. And put the parentheses there. And now, instead of console. log result, we're going to delete that and do return result. You'll see this is not complete yet, uh, but we want to see what do we get out of this. So, save it. And again, this is just get quote. What do we get? We get this big JSON. This is, you can sort of see it right here. Quote, play it again. Sam, as time goes by, we get a whole bunch of stuff. Use Random Quote API in Google Sheets Fast FAQS Automatic Screenshot in Google Sheets
Okay? We don't want all that stuff. What we want is const j, uh, all lowercase json equals json uppercase parse, and we want to parse the result. And now our return is going to be json dot, and we're actually going to do in bracket zero, and then another bracket in quote. Uh, and now if we hit save. Our big JSON will probably change, there it goes, it changes to one exact quote. But we don't want to have to just do this, uh, we can actually edit this from ten to one. It's up here in the count, we're just going to do one. And our category movies, what's that? Spreadsheet Automation 101 Lesson 4: JSON (beautifier) and OmdbAPI parameters
Well, in here, we'll have, should be in the about section, somewhere. Hmm. It says current categories are famous and movies right here. So, what we're going to try is instead of category movies, we're going to do category famous. Command S to save. Make sure this saves. Yeah, it saved. Done. And now we have a random famous quote. So we can actually rename this famous quote. And now every time we use this function , it'll give us a random famous quote. So we have a working thing here. Use Random Quote API in Google Sheets Use Random Quote API in Google Sheets Quickly Build a Daily Random Motivational Quote Website
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 code, but In, in the function , say famous or movie, well, let's see how we do that. I'm going to show you. 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. So inside of here, we'll, 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. Use Random Quote API in Google Sheets Use Random Quote API in Google Sheets VIBE CODE GOOGLE SHEETS
And category. So we'll fill in the category, famous or, we know famous or movie, for this get quote. We'll save this, we'll change this to get famous quote. And now we want to say get, actually we'll just do quote equals get quote. And inside we need to put in parentheses famous, We do exactly the same thing, but insi inside we do movies. And there we go. Now we have a movie quote or a famous quote upon whatever text we put in here. We will start getting errors, I think, if we, let's see what happens if we Use Random Quote API in Google Sheets Use Random Quote API in Google Sheets
don't put it, see if we do it wrong, bam. We're gonna get nothing. What we might do here is put some kind of if. Category is equal to famous, or category is equal to movies. Was it movies or movie? Yeah, movies. Uh, and if that's the case, then we will do all of this stuff that we're doing. If that is not the case, meaning we neither put in famous or movies as the category,
we do else and we'll return, hey, need to put in famous or famous or movies. 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 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, uh, thankfully you watched this whole video, and, uh, really hoping you can use some more RapidAPI. If you do use RapidAPI for other APIs, let me know. I'm happy to see other use cases. Use Random Quote API in Google Sheets
I think this is a really simple one, and I love that RapidAPI has this code snippet for us. Again, JavaScript. Fetch is the way to get that code snippet and start using it. And we just have to edit a little bit for Google Sheets. Bye. Use Random Quote API in Google Sheets Learn to Code in Google Sheets, For Programmers | For Advanced Google Sheet Users Access Free API's with Google Sheets Scrape Google Maps in Google Sheets