How To Connect Api With WordPress - Full Guide
3K views
Feb 20, 2024
How To Connect Api With WordPress - Full Guide
View Video Transcript
0:00
how to connect API with WordPress. Hello, everyone. Welcome back to another video. I
0:05
hope you all are doing great and are having an amazing and absolutely incredible day
0:10
I bring you back with yet another video. And in this video, we're going to be talking about
0:14
an API and how we're going to allow ourselves to connect it with our WordPress in the easiest
0:20
most simplest way possible. So basically, connecting your API to your WordPress is pretty
0:25
simple. Okay, we're just going to be using a few different methods. Okay, and obviously
0:29
connecting an API comes into coding, okay, because API obviously is a code for any different
0:35
design that you can add into some other design. So let's say, you know, for example, I want
0:41
to add a chat GPT, you could say, API into my website. So chat GPT obviously has given
0:47
their API. So they have an API key, I'm going to choose any other API keys and just, you
0:53
know, add their API into my setting. And that should be good to go. But yeah, so to
0:59
add an API into our WordPress website, where you're going to do, first of all, you're going
1:04
to come over to plugins, okay, once you come over to plugins, over here, you're going to
1:09
write w p, get a p, okay, you're going to write that and you're going to click on Enter
1:16
nearest s connect external API is WP get API. So we're going to open this up. Now obviously
1:22
you can start seeing the details about this API down here. So connect WordPress to external
1:25
API's, send your data to API's and display API data using shortcode to template tag
1:31
connecting to API's has never been easier. You can see all these things easily send data
1:36
to any API, get data from unlimited third party rest API's format and display the return
1:42
data on your WordPress website using a shortcode or a template tag. WP API gets or supports
1:48
visually all authentication methods, okay, including API keys, bearer tokens, basic authentication, username, password, and OAuth 2.0, which is pretty good. And then they also
2:00
give you live examples for videos that you can connect to WordPress using external API
2:05
And you can also see the major feature so you can connect your WordPress website to
2:09
any of the API's unlimited API's are allowed. No coding by you is required. Like, obviously
2:17
you're just going to provide the API code. Obviously, that is a must. But apart from
2:22
that, no coding, then the display API data, you know, using a template tag or shortcode
2:28
is given, you can add query strings, headers and body parameters. That's the only like
2:33
line of code you want to do. So pretty easy, pretty simple. Now all you're going to do
2:38
is you're obviously going to make sure you have a business account. Now if you don't have a business account, you are going to need to upgrade to that. Because without a
2:45
business account, you will not be able to add any API, you know, or get a plugin. Now
2:51
once you have a business account, you're just going to add it or you know, add an API into
2:58
your WordPress. Once you've added an API, basically what's going to happen from there
3:02
is you're going to get it down in your plugins and tools. Once you get it down in your plugins
3:07
and tools, it's obviously going to ask you to set up so it asks you to add the details
3:11
of the APIs that you're using. And the endpoints that it will give will be set up in the next
3:16
step, you know, after you hit save. So what happens from there is it asks you three things
3:22
you know, it asks you the API name, unique ID and base URL. So API name is the name of
3:28
the API that you are connecting to, then there's unique ID, which is a unique ID for your API
3:33
So lowercase letters and underscores only are used. And then finally, there's base URL
3:38
So the base URL of the API is like, obviously, the base URL of the API that you're connecting
3:44
to. So yeah, basically, to get these things for, you know, any program, you're going to
3:51
go ahead with their thing. So to get this from an API, let's say I'm going to come here
3:56
to chat GPT. Okay, go ahead and chat GPT. I'm going to write API in front of it. Okay
4:05
so this chat GPT really popular thing, and let's say I want to chat bot in my website
4:10
So I'm going to go ahead to chat GPT API, and I want to, you know, copy it off. So here
4:14
we can see introducing chat GPT and whisper API is developer can now integrate chat GPT
4:19
and whisper models into their apps. So to get their API, they're going to come down
4:23
here, and you can start seeing their APIs. So it's pretty incredible, pretty easy. And
4:30
you can see all these different things that they've given you. So this is the chat GPT
4:35
API. Now, you know, chat GPT model family gives you token and here's the API. So it
4:42
gives you a model as a sequence of tokens, which is pretty incredible. So this is your
4:47
API code. Okay, so all you're going to do is you're just going to go ahead and copy
4:52
it off. Okay. And once someone copies that off, this is the response they get it with
4:57
the Python binding. So you're just going to copy it off. Once you copy it off. Yeah, basically
5:03
you're just going to come here. And when they ask you for the API name, you're going to
5:06
add the API name, your unique ID is going to be the key that is going to be provided
5:12
to you through open AI. So if you go into this over here, this API, you can go into
5:19
overview. Okay, you can choose their API platform and to choose their API platform, obviously
5:25
sign in with your accounts and everything. And yeah, you can see on chat GPT, you can
5:31
just use any of their API APIs from the input over here. Or you can even like this is just
5:35
a common example of chat GPT. You could use any software, let's say you want to connect
5:40
it to Google Maps or something like that. So you know, add the API name, which is obviously
5:45
chat GPT, then there's the unique ID that which is the unique key that they're going
5:49
to give you in the base URL, which is the URL website for the API. So I'm going to come
5:55
here and this is the URL website. So I'm just going to copy this link, go ahead and paste
5:59
it in the base URL. Once you've done all of that, you can start getting random quotes
6:04
as well or the API's. So after adding the base URL, it takes you to the actual, you
6:12
know, once you've saved everything, it creates one endpoint. And that basically creates different
6:18
template tags. Now, template tags are basically, you know, lines of code like WP get API, which
6:25
is WordPress get API, which is a code that WordPress generates. And moving on, they have
6:31
different methods and endpoints. So in the endpoint, in unique ID, there's obviously
6:37
a few things that you're going to need to add, so you know, JavaScript and all that
6:41
So all these necessary things need to be added. And you can, you know, create a results format
6:46
for those. And all of them obviously are going to be done using your basic WP get API
6:53
and WP get API obviously walks you through everything. And there's a unique ID for the
6:57
endpoint, the endpoint will be appended to the actual base URL. So you're going to click
7:02
on you know, get slash chat, GPT slash, you know, whatever your API name is. So chat GPT
7:09
in this case, that obviously there's the method. So request method for this endpoint, obviously
7:14
you're going to use the get method, which is basically going to just going to get the API and the get method is all in capital, which is a code in JavaScript. So it gets
7:24
things and the results format, result format is obviously going to be the one that they
7:30
were telling you. So in chat, you would use case it was Python, you're going to go with
7:34
Python build. Once you do that, it gives you cache a time, which is the time in seconds
7:38
that the cache requests everything. And once you say all of that, it's going to basically
7:44
give you the whole code and everything. And it's even going to give you the URL. And it's
7:49
going to give you the response that it gives you. Now, if the response is identical to
7:54
the one that we saw in chat, GPT, you know that we sign products over here, then you
8:00
did the right thing. And you know, you're good to go with whatever API you've made
8:03
But if the response is incorrect, you've done something incorrect, and just make sure to go ahead and do it all again. And everything should work fine. But yeah, that was basically
8:11
about it for when it comes to discussing how you're going to connect an API with WordPress
8:15
That's pretty much about it for this video. So thank you for watching till the end and I'll see all of you next time. Goodbye