 So we are going to add on to our project and now we are going to introduce the API Domain Checking System. The way we are going to do this is first of all query our API, bringing the results that we see and we should be able to cross check them here on our page before we can integrate the form that we do have and the API itself and you must be thinking this must be something that's really really complex but in reality we use APIs on the daily. Every time you use your Gmail to sign up in another place or you use your Facebook or you use Twitter or GitHub to sign up for another third party account you are using the API of that particular system. You're using the GitHub, Gmail or Twitter API and that's basically allowing that particular third party to access your information on the other website to populate information on their end. Now this is only possible with APIs and that's basically an interface or a way or a channel that is provided by one particular system whereby they give you access to their database or information that's limited so that you can be able to use it in another place. The UG registry also has a similar platform for us so I'm just going to go and log into my account so that we can be able to see the documentation of how to use that API and when we're using it we're going to first of all test it with Postman to see what particular pieces we need to have in our body in our headers and in the different areas before we can integrate that into our particular plugin and when we're logging into our interface we're going to find that we have two versions of our documentation so we have version one and version two in version one we're actually going to find out that it is written in XML this is how data was transferred earlier on before we eventually came up with something that is dependent on JSON so we have two different APIs but both of them do work now the reason I'm going to share how to work with the XML is because a number of you have been asking me how do I integrate XML, how do I integrate SOAP and SOAP is basically a system that was built on XML so we're going to be able to see how to handle XML requests inside WordPress because the way WordPress works is that they have conversed or they have enveloped the call request that we are going to see right here so you will see that in this XML they tell us hey use call if you're using PHP and WordPress has a class that has different methods and it wraps all of this so that you can use it simply and we're going to be able to see that so I'm going to go back into my WordPress install and what I'm going to do here is I'm going to check the WP includes folder and I'm going to say find and I'm going to look for the wpremot underscore get and when we go to this file which is the http.php file inside our wp includes you're going to see these different methods the wpremot get wpremot request and we shall see that these methods they require two arguments to be passed to them the URL of the API and some arguments that we are going to be able to see but you find out that these are a wrap of this particular function so if I click on this I am able to get this function and you're going to see that it's also wrapping this class which is called wp underscore http and if we click on this we are able to go and see how this particular class is wrapped and you'll see it has request methods in here and you can study this class to see all the different methods and action hooks in it and you're going to find that they nicely wrap everything that you would need when you are making an http request to get all the data so this makes it really simple for us first and foremost I'm going to show you how we can handle this in postman and once we're able to do that in postman we can be able to translate that knowledge into other API systems my goal is not just to show you this or help you build the domain searcher but to give you a vast amount of knowledge so that you can be able to build your own API tools so let's open up postman and this is a free software that you can download by just googling postman download it install it and then you can be able to use it so I'm going to go and check out firstly the API that we need to use here and I'm going to use version one of our API and we can see here in the section where it says how it works we are told that we need to have an http post that's a method and there are different methods there's get, there's put, there's delete and so many others but we are going to use the post method and this is the server URL that we are going to use so I'm going to copy this bring it in postman I'll click to add a new tab I'll paste this but I'm going to change this into a post method and once we have the post method turned on the next thing we're going to do is we're going to look for an example of what we need to make as a request and here they tell us that we need to use this XML request here and this is how we can test for any URL so I'm going to go back to postman and because this documentation is a bit convoluted like it doesn't tell you where do you need to have this particular information the first place I'm going to do is check inside the body so I'm going to go here to the body I'm going to choose raw and I'm going to choose XML as my default setting and when I paste in this you'll see that this is beautifully formatted and we are ready to go so I'll reduce this to just two so that we can check out number one I'm going to use a government domain which is for the revenue authority here and that will allow me to know that this is actually already taken up and then I'm going to just check for take a press to see whether this is available so once I do this I'm going to click send and you will see that we get back a nice response which is also in XML and it's similar to what the success story is supposed to be we know that we need to send this information in the body we don't have any other limitations but we're going to see some of those limitations in the future like where you need to add a password or you need to first generate a token and then embed it inside your code so with this we are able to go and write code for our XML so that we can see how XMLs work inside Wordpress I'm going to open up my editor and here I'm going to write a new function and I'm going to call it check availability so in here the one thing that I'm going to do is I'm going to use our wpremot underscore and I'm going to go for the post because by default this is the method in Wordpress that allows us to do an HTTP request but with a default method of post now in here we need to pass the URL and then we need to pass some arguments of course our editor will begin shouting at us and tell us hey you have not defined some of these variables that you're using so I'm going to go and say the results should equal to this and then up here I'm going to start defining the URL and we just need to go back to our documentation or to postman and say yeah we have this ready here so I'll copy this paste it in here clean this up to remove the extra space and then for the args this is going to be an array of information and inside here we can pass a number of things we can pass the method we can pass the body and then we can as well pass some headers now of course this would have to be erupt in quotes and since this is an array we need to chain on some items in here for example the method I'm going to use here is a post method and the body will be empty equal sign with a greater than symbol and then of course chain this and I'll just add some space here to have this vertically aligned and the body of course can be an array of information it can be anything and then the same thing goes for the headers so I just need to copy this paste it here and this is how we can pass our headers our body and our method now in our particular case we were just passing a string inside the body so this is a string so I'm going to copy this I'm going to come back here and say this is our body and I'll say this should be in quotes and add a semicolon here to make it terminate well and I'm going to copy this and replace it with this item here and inside the headers we're going to have to pass something because the way this request works is that it uses JSON but we need to tell our API that all the information we are sending is actually XML so in here we are going to have a content dash type and then we shall say the type that we're going to pass is actually application slash XML and this could have been anything it could have been JSON it could have been HTML it could have been anything but because we are passing XML we're going to have an application slash XML in here so because this is just single line of code I don't need to put the array on different lines I'm going to move this to one line and after doing this all we need to do is say let's JSON encode our results and the reason I'm doing this is so that I can be able to visually see it and I'll say results is equal to this and what we want to do at the end of the day is we want to va-damp it so I'll say va-damp and va-damp is a php function that allows you to see everything on the front end and I have a nice video that I'm going to add to this playlist or just link it up in the video right in the top corner in the details body so that you can see how to use va-damps and how to use error logs so that you can be able to see all the information that you want to while you're doing your different queries inside wordpress I'm going to now copy this method right here I'm going to pass it in here and say let's run our function which is a check availability and that is every time we run our shortcode so click save I'm going to go back to our browser and then go check on the front end reload this code of ok and then we have some details here that are not being passed this is not relatively clear for us so what I'm going to do is go back to our code and instead of va-damping whatever we're getting here I'm going to change this into an error log and inside here we're going to do print underscore R I'll put a semicolon so that I don't forget it I'll add our results here and say this should be true so instead of just printing a string of results we want to output everything that comes inside our results and what this error log will do is that it's going to dump all the details inside a debug.log file now in what price the debug.log file is usually in the wp-content folder but sometimes you will not find it there because it's not automatically available now we can be able to enable the debug.log file by going inside our root folder we go to the wp-config.php and inside here we're going to scroll down and we look for the wp-underscore-debug constant and here we see they tell us that it's false so we're going to change this to true and the other thing that we're going to do is that we're going to define another variable which is the wp-underscore-debug-underscore-log and we'll say let this be true and this is going to allow us to log our php errors so once i come back here i'm going to go back to our front end run this again of course there will be nothing visual here for us to see but when i go back to my editor you're going to find that now we have a new file inside the wp-content and when i click on this you will see that we have more information available to us we have this node which is the body we have the response which is 200 and which is okay and we have our response right here in wadpress now i'm going to target this body so i'm going to target that by coming here and saying we need to use the method in wadpress which is called wp-remote retrieve and we want to get that body it requires us to pass only one thing and that is this response that we get from querying this and we'll say let's call this body response and i'm going to just error log this so i'll save this i'll go back to our debug.log i'll clean this out so that it's fresh go back to our browser i'll reload this and when we go back to our editor and look in our debug.log you'll see that this is nice and clean so this is something that we can use to play around with javascript and so on to be able to get this information now the thing with xml is that everything comes back in a node and in modern languages it's relatively hard to work with the individual pieces of code so it would be good to transform this into json that we can then use in our application i'm going to comment this out and in php we have some methods which allow us to change xml into json so we have this simple xml load string let's get our body response pass it in here and say this is our xml string after loading this string we're going to say let's get our json by saying let's json underscore encode this so we'll have the dollar sign with xml and after doing this i can be able to vadamp this finally so vadamp and say let's get our json add a semicolon at the end here we'll come back to our browser hit reload and you will see that we have some new information in here so this is giving us the domains the attributes and everything is available and the one other thing now i'm going to do is just convert this into php so that we can then use it properly so i'll say this is php at this point we're going to change this to json so we have our json we're changing it into a php array and instead of encoding we're now going to decode so we decode this let's vadamp our php come back to the browser reload and you're going to see that we have this in a nice node right here of data and if we want to make it even seem better let's echo some pre tags here i'll duplicate this and then just add a slash at the beginning so save this come back here reload and you'll see that we have this coming out very well inside an array and we can pick this data and use it effectively so that's how we work with xml and in the next video i'll be able to show you how to use version 2 to get everything inside json so that it looks as neat as what we have here then we shall be able to join the to the form and the data that we're getting back from the api and then build it into something that is neat as we initially planned to have here if you enjoyed the video please give it a thumbs up don't forget to share this with your friends and leave me a response i'm letting me know what you think about the video or if you have any questions