 Alright, welcome back to the channel. In today's video I'm going to attempt to answer a question that I get a lot and that is how do you add header parameters when you're trying to query an external API, whether it's REST or whatever it is outside of WordPress and you want to bring in that information into your WordPress, then you can use it maybe in your custom post type or even just display it on the front end. So what I'm going to do is I've found an API that is open, you just need to sign up and you'll be given an API key like what I have here and once you're able to do that you should be able to query this particular API and then use it in your WordPress. If this is something that you want to see then let's jump into the code. So I'm going to open up my editor in VS Code and I have opened up the plugins folder. I've added this new folder and I've added this file just to start up my plugin as well. I'll write some PHP here just to get us started and I have this little snippet that allows me to add the plugin starter information for any plugin that I want. So I can just leave it here bare and I'll say this is going to be add headers to API call and that will be the name of my plugin. You can as well go and feed in all this other information. So what that will do for us is that when we come to our plugin section in our WordPress install, we now have this plugin that we can activate. So I've activated it so that I'm able to run it at any time. Now I'll go back to my editor. In my editor the first thing I'm going to do is add some bit of security and that is just to make sure define the abs path so that I'm not accessing this file directly. So once I do this, this is just basic security and then I'm going to come down here and the first thing that I'll do is I'm going to add a new menu page which will allow us to see the results from my API call and then eventually I'm going to make the API call with headers. First let's tackle this. So I'm going to add a new action from WordPress and here I'm going to check for admin underscore menu. That's what I want to work with and I will say let's have this under the take a press add menu as a function and this is going to be the name of our callback. So I can add this function here with that name. So in here we're going to use a method from WordPress which is add underscore menu page and this requires us to have a page title. So I'm going to come to the next line and say our page title will be pinging the API with headers and that's going to go to the top of the page. Next we need to add a menu item where we'll say API ping and that will be on the side menu and next we need to add some capabilities. So I'm going to add a capability of manage options and then we need to add a menu slag. So the menu slag is going to be like take a press API ping live dot PHP then we need to add a callback which I'll say take a press underscore ping then we need to add an icon URL. So I'm going to use dash icons because these are free and I'll say let this be the testimonio and you can use any of the dash icons available and then finally we can add a position which I'm going to just choose to be 16. So I'll add a semicolon here and then with this we should be able to get a page coming here and when we come back here and reload this page you'll see we have this ping and right here it's telling us we don't have this take a press ping callback. So I'm going to come back to my editor I'll copy this I'm going to make a new function add it here and then of course in here we can do a number of things. So I'm going to close my PHP and open my PHP again that will allow me to write some HTML markup in here. So the first thing I'll do is write a div with a class of wrap and then I can add an h1 where I can say testing API results and after doing that I'm going to use a wp remote request function which is from one press itself it's part of the call and this requires us to pass a URL and in here we can pass an array of arguments like our code editor is highlighting and telling us to do. So I'll save this as ping results and I'll assign this to this variable now what we need to do is define our URL this is going to be a string we need to get it from our API documentation. So I'm going to come back here and you see we have an example of how to use this API in JavaScript you can choose even PHP like Carl and so on. So I'm going to use the URL that's in here but I am not going to use this particular endpoint because it requires us to have an ID that we don't have a clue about. So I'm going to go for the series and I'm going to copy this URL copy it come back to my editor I'll add this in here and then we can also define the argument. So the argument remember we say it is an array so you can use this square brackets or you can use the old convention of the array text now inside here we can define quite a number of things for example we can define the method whether we want to use a post get update put delete whatever it is and this particular case we're going to use a get method now after the method we can also have the headers and the headers is actually an array of items now you're going to see that in a little while and we can also pass a body to this and this is also an array of items I need to wrap this into quotes because it's a string I'll tab this in one place so that it makes it easier for us to read and then when I go back to the docs you'll see that in our headers we are required to pass these two items that is basically the X rapid API key and the X rapid API host URL I'll copy this I'll come back to the editor I'm going to paste them inside our header here so this is the finished product but we need to pass this as array items so I need to wrap these in strings and then pass our arrow function here I'm going to change these double quotes into single quotes and then I'll just do the same wrap these in quotes and then add our arrow so this is how we know that these are the headers that are supposed to be passed now in order to test this I'm going to do a VADAM and I'm just wrapping this up with some pre-tags so that it can format quite well now I'll copy our picking results here and put it here in the response I'll come back to our browser and make sure that this is ready for testing so I can test the endpoint if I want to from here but I can come back to my page that I've prepared click the API pink and you will see that we actually get back data flowing in from the body here now this is very good this is actually what we needed but if we go back to this API you'll actually see that I'm subscribed to be able to use this API but if you check out the pricing you'll be able to see I'm using the basic free version that has a limit of 250 requests per month and I can only do one request per second or 60 requests per minute so you might have to store this information somewhere maybe in a database or in a custom post type and I have videos where I already show you how to save this data in custom post types or in a database feel free to check my channel on how to do this but if you want to see how I actually get this and move it and put it in another place like a custom post type or whatever I'm going to create a video that I'll throw in my membership section so that the people who have subscribed to this channel and are members paying a little bit of money to support this channel can be able to actually see this in its full entirety let me know in the comment section about what you think about that otherwise enjoy whatever you're developing and you can be able to use this API whenever my goal was to show you how to add headers inside your request for the WordPress API ping