 So for us to post our information from the API, we actually use wpInsertPost which is a wordpress function and all it does is that it inserts a post, it can post all this information that comes usually by default to posts but you can also add your own meta values inside that post. So we have an example here whereby we are getting a post object and then all we are doing is we are inserting it inside that post. So what I'm going to do is just capture this and then I'm going to go back to our outgoing SMS and then I'm going to paste this inside our function that we created and we actually called store inside SMS. So I'll copy this and then I will punch this right here. So I'll save this, I'll add a semicolon and then I'm going to pass in the response here so that it can be used by that function. So we'll have that as an argument and save this. So what I'm going to do is go back to my techie press allow for one more SMS to be sent and when it's sent we shall be able to see the post object that we actually get back in our outgoing SMS. So fast and foremost, I just want to get the response that comes back. So save this here, let's go back, hit our SMS plugin and we'll see that we get information coming back in our body. We have a status, we have a cost right here. Of course the headers give us that it's a status 200 and so we're able to differentiate, we're able to show the different statuses given the different feedbacks from the status code. So we know that while we were sending this data send API we had different pieces of our object being sent to this particular field. So we'll pick the information from here and then we shall add it to this. So what I'm going to do is actually just strip off this JSON encode at this point and what I'm going to do is that I'm going to add it here at the point when we are sending to the body so that I can actually reuse this particular object. So I'll get this little API I am able to get the user data or I'm able to get the message data at this point. So I'll get the data and then that's what I'll be passing to this particular field. Now in our poster we don't have a title we don't have content we don't have the status is published that's okay. We don't need to add an author in the category. We don't need the content. The title will will fabricate our own title but I'm more interested in adding meta keys at this point and at this point we add the meta by adding meta input. This will take in an array. Inside this array you're actually able to add the different meta fields that you do need. So for example I'll add data send API onto that I am going to map the message message data and then onto that I am going to map the number. Now inside this meta out meta input I just need to go back to this file and I'll look up what are we looking for? We are looking for the sender ID number one we are looking for the message status we are looking for the message we are looking for the send numbers. So number one is we are looking for the sender ID and that comes with this meta key so sender ID meta key come back here I'll duplicate this so sender ID meta key what we need to do is actually get the sender ID at this point and add it here. Next is we are going to need the numbers so we are going to get the sender's numbers field so I'll copy this and add it in this meta key and add it in the meta input then I'll duplicate this come back get also the message copy this here and then we'll pick the message from here copy then we'll add the message for the message field and then finally what we are doing is we want to get the status we want to get the status as well so I'll duplicate this and add the status now give or take the status is going to actually we are going to get the status from our own stored status so I'm just going to pass this in inside this field here we are going to pick it from this point when we actually pass in our response in the different fields so I'm going to copy this response so we are going to pass in the response we are going to pass in the status and I also want to pass in the data send API data so I will pass that in as well so that we can tap it we can tap this then from the response we are going to be able to get the response here we are going to get the code for the response and depending on the code that will be the status we shall get our status from that particular point so at this point let me just get the status so the status will be equal to the WP remote retrieve and at this point we are going to get the header or the status so we want to get the code and we shall pass in the response at this point here so if our status at this point is equal to 200 so we start off with 200 is equal to status and we can make this three equal signs then our status will equal to success shall pass in a string of success to show that it actually went through and then if it's anything else then our status is actually going to equal to failed so duplicate this move this down and then I'll call this failed so we know that we are actually going to pass a status from here which is either success or failed so when we pass it in here we are actually working I'll uncomment this when we pass in we need to pass this in in their particular order so when we pass in the status we know that the status will either be failed or it will be success at that point so data send API will give us different information we need then what we need to do with the response here is actually we want to get the body and then get the status if it's okay we need to find the cost I'll comment this out for now then what I'm going to do here is actually get the WP remote retrieve body and I'm going to get the response here so this will give us our results I'm going to JSON decode this and then after JSON decoding our results I'll be able to get the different this is so from the results we'll know we'll get the status whether it's okay and yeah so we're going to get the cost we're also going to get the status so at this point I can actually just get the status by saying result then append this and get status here so we can do more refinements to find out if everything else works out well but we'll just add this as a status so okay or fail will be coming from there so we don't need to do much of this at this point here so I'll just delete this and keep what comes in by default here I'll also remove this point here and then fail it if we have a failure then I'll automatically fail this so that means here at this point I need to return so I'll I just need to return so I'm going to return this and then delete this meaning nothing else will be executed but if everything passes out well we have a status of 200 we should have this showing up here run this function passing this data and then passing the status here and then what I'm going to do is just add another field and then I'll call this SMS cost so we'll have an SMS cost key here and then from the result we shall have cost so meaning come back to our admin fields here and then we shall add also the cost so I can just duplicate this and then I'll I'll change this go back here look at this key copy it come back and change this SMS cost key and then I'll edit this so we have an SMS cost key here same key we shall have here and then I'll just get this also and change this sender ID to SMS cost and save this right here so if we come back to our messages we still also don't have this showing up so we'll have SMS cost and then we shall call this our cost at this point so allow me to just make one SMS send out after saving this and let's see what we actually get so at the end of the day we will have gotten all of this and then passed in we just passing into our post and then we'll see that we actually get our SMS so let me click this we have our SMS showing up and then go to the messages so we're not seeing that here because we forgot one argument here we should actually be post type so we'll add our post type and the post type we're going to add this SMS so I'll save this and the moment of truth hit SMS plug in here see what comes let's check here we'll see we have edit a new post was created which is successful however we did not get our information showing up before we send anything here let me just update let me get an update option so that we don't send so many SMSes we shall later delete that option so SMS result that will be our option and what we're going to do is we're going to save our response so let me just get this right here let me just get this as response terminate it here save it let me get this as our response then I'll save that inside our value and then we shall use that to save our data when we can see what's going on so let me hit that again we have that so let us get our option get option and the option that we're going to get is SMS underscore results and then what we need to do is we've add dump it and save our reload and we have our first value of status here so in this case if we're adding so now we have to always check when we're sending SMSes we actually don't have failures of not having enough money if I JSON decode the response that we have here I should be able to get at least from the response I should be able to get that status which is failed as we publish to our SMS so let me and do this save and then reload this and get failed status when we go to messages I have two messages and we have our status of failed actually can be right there so that's brilliant so what I'm going to do again here is instead of wasting our failed we should be able to add our message here and say for example when this happens when we ping and we have our message here we should be able to add that to our status I'll come back here status and then append using two dots I'll use space in between add a dash and I'm going to get results then I'll add on the message result then I'll add message so save this this is not the best way to do this I should be able to cross check if this actually works out so I'll reload this we have a failed come back check this and see our status of what's happening here now I just need to find out why I'm not getting my data send API message and then getting the sender ID showing up here so let me get this and then I will over down that save it let's go and send so I have my method and then inside have user data and I have message data let me also overdump like sender ID to see what's happening reload and it is now so let me save this reload this is also now so when we dump this we will actually see that this is decoded it's a json encoded I don't know why it's json encoded but let's try to decode it and see if we will save our data so ah the reason we are doing this is we are getting that object wrong in how we send this data so I'm just going to append a few elements here wrap this in a single quotes and do the same for this so wrap that in single quotes and then we should be able to do the same for all the others copy this paste this then just get the number here cut it paste message cut paste and save this the missing piece is actually adding that this is the first array of data so we add zero to this and then we'll add zero to that then we'll take away our dump that we are having here save this come back to our messages let us just delete everything here that's there go back and send so we have a message success when we come back here we have a message click edit we'll see that we have our ID we have a cost we have a message we have the numbers and this is working out brilliantly this is what we needed to do so we can see that our data now actually comes back because we got everything right so from the data that comes from our object up here we just need to pass it into our store inside CPT and then pass it in here get the message but because we know that's the first array that's coming in then we add the zero and then we add the sender ID or the number or the message to actually wrap all of this here and that's why we're getting all this information here now just to make this a lot clean and better for the UI we know that the cost is going to be zero so in the event that we have an empty or null cost we should now start sanitizing this and know that if it's empty or if it is null then we should throw back a zero so we need to add some if statements and let me just get this and wrap it inside a variable so I'll just get a variable called cost here and it's at this point where I'm going to get the cost is equal to this and then wrap here so I know if it is not equal to if it's not equal to null we need to do this in a yoda format so null would be zero if it is not equal to null or if it's not empty or not empty so not empty if that is not empty then we shall get that as a result else then cost will equal to zero as the value so we'll save that we need to just wrap this properly and then yeah terminate this save we cannot use this over and over again so I'm going to copy this then just say cost cost as that and then I'll come back here and say cost is equal to that save so we have it here if it's not null or is not empty sorry if if cost is not null and is not empty then the cost will equal to that however if it is empty or if it is null then the cost will be zero so let's try to do that we also need to check this if this is not empty if this particular field is not empty then we can add that we have a couple of things to check that whether they are empty or so and so we need to check we need to sanitize all this data that's going inside our database so we need to be very clear about how we do this so I'm going to just try one more time to see what's happening go back to our messages check the second message and we'll see now that we have a cost of zero we have our message we have everything working out well and that is what we are looking for so the only thing that we need to do is actually just show these numbers on the admin side and then we'll wrap up this video I'm going to go back to our custom so we're going to use one other filter to add our content in there and it's called the manage and we'll use our post type which is SMS post column and this is a singular so custom column so custom column and this is singular and now in here we're going to add data so take a press add custom column data so I'll copy this and then I'll just start up a function here and then I will add this data from this point so we're going to be looking for the different pieces of data as we've stored them in these different columns we need these columns actually right here so I'm just going to press them here to make it easy so we're going to do a switch statement but first of all this filter alone gives you the columns gives you columns coming in it also gives you the post ID that you do get so I'll just utilize those for now so we're going to a switch statement and we'll start off with switch and we're going to switch for each column that we're getting so this is column not to not to to confuse it's just singular columns so we'll do a case and we'll say for the case where we are looking at the sender ID here all we need to do is we're going to come and we're going to actually echo and what we're going to echo is similarly what we've been doing here so we're going to get the post meta sender ID true and I realize in these points we did not put semicolons which is very bad PHP but we are getting away with it because it was just one line of code so making that correction here so I'm going to come and echo this and terminate then I need to break this because I'm done record and I need to break so I'm done for the sender ID so for example let me close this let me save that let's have a look at what's happening here and we have some issues showing up because I passed the wrong post ID so I need to copy this paste this here the reason why this is also broken is because I did not pass a priority and also talk about the two and also don't talk about the two arguments that I'm actually passing inside this function so let me save this and then when I reload this you'll actually see that we have a sukuma coming from our ID here so let's add all the other pieces and see how that evolves so we just need to duplicate this and then we shall get the different pieces so send paste here send number count we shall have to count the numbers are in there status SMS status shall add the status cost shall add the cost in here so just need to get the other pieces send numbers send numbers field is going to help us with our count shall write a function for that we have the message field come back here paste it in our message and then we have the send ID cost get the cost counted for us here and then we just need to get the status also so get the status and add it here so save this after cleaning this out save this and reload and we have our values showing up here with this at hand let me just add some credit to my account and let's try a successful message let's try this one more time reload and then let's hit plugin get a response that's okay let's go back to our messages we see that we have okay as a message and our phone just buzzed with our message we can get it so this is how this looks like we have a couple of things to do in our code to make it cleaner to sanitize it because all this data is going inside our database we can make this also look just a little bit nice wrap it with a span and add a little green color to it make this with a fail maybe pink or red color just to distinguish it to show what's happening so this is how we are doing this and how we are showing this inside our custom admin I hope this is working out as you thought it would let me know in the comments what you think about how we are heading how we are doing this are we doing the right approach should we just throw all this content into a custom database or should we keep this as it is for now this is going to help us to do all of this but I'm going to set up and show another admin side whereby we can actually just create our SMS and type inside our boxes verify that we have enough data because our database right now actually knows how much we have on our account to be able to allow us to send a particular number of messages so in the next video we'll be looking at the number count we'll be looking at the admin side to make sure that we are doing everything correctly thank you for watching the video enjoy your coding