logo

NJP

#Part 9 Create a REST request to get the daily summary- Covid19

Import · Jun 04, 2020 · video

all right everyone so in this video what we are going to learn here is to create an action info designer in order to send a request to a third-party api's so we can get the response and once we have the response we're gonna pass the response and later on I will be showing you how we can store the past response into our coffee 19 table okay so the goal here is to have the daily updates so if you have cases how many cases that we have for today for all countries so let's create for an action in flow designer so look for action here click on create and give it a name for your action and then I'm going to put here get daily summary Kona API so this is kind of the API that I'm using you can sum it and the first part of the action is basically send a request and rest requests specifically and select here connection is going to be defined connection in line this is our endpoint this is the we are there that we are going to use not to get all the result so the base URL is basically the HTTP Karuna API dot-com and the countries are we put in the resource path okay so and let's have some headers here and I will have content type application Jason so let's give it a title so it couldn't be for example get summary one then enable to try policies save your changes and then now we are going to create our script so basically the script will give me parsing the response okay so FAR's summary one response body this is going to be the title and we have two input variable the first one is going to be status code and the second one is going to be response body where we will have all our response okay so I'm taking the data files and just dragging and dropping into the value section so the first thing in my script here is to create an array so I will have a summary one area which will have all the results and then going through the condition the basic condition that you have to test if the response is successful or not we are going to check we have a status code 200 if yes execute everything that I have inside my inside the curly brackets my if condition okay so here the first thing we are going to do is to pass the response okay we have a response in our response underscore body variable it's the input variable so far response body I'm creating a variable another one which will basically contain all the past result so I'm going to have here for example Jason dot parse and then inputs dot response under school boy so I'm going to pass the response body and put it in my response body variable so I can use it later so then I'm creating me for loop and I will be explaining why we need a follow okay basically the if you see the jason response that we get from the third party API is we're gonna get an array and we have specifically there a data variable which is an array variable which contains all the result for all countries so this is the reason why I am using here loop and I'm gonna move into the Eric so I have a data area here I have only the result for Afghanistan but if you have four if you have the result for multiple countries you have the same structure for every for example for another country for India or Pakistan you have different like the same structure will be repeated so I'm using the array and I'm going to until the end of the length of that data arrays okay so not end of the length I'm taking the length I'm going until the entire length so that will be my loop in my loop I will have first thing is to create an object so for summary one object and that object me to have two specific values here you have confirmed cases and then recover this summary one object are confirmed we'll have what we have in the response body specifically for country cases so response body then data array so we specify for which and put I variable here so for theta zero for example which is kinda stand for example and then we could go to latest underscore data dark confirm so laters underscore data is one of the object that we have in the JSON response so this is how we can take the data from our response okay from the JSON response so let me show you what we have here we have latest underscore data this is in our data this is our in our data object and then we have all the confirmed cases of our cases and so on so this is how we can get to that result so response body dot data I doubt latest underscore data of confirmed cases okay we are going to do the same thing for recover cases we are running a loop in each iteration we are going through the array that we have here and data 0 theta 1 theta 2 theta 3 theta 4 theta 5 f6 so on and we are taking the confirmed cases number of cold cases number 80 correspond and the result for you will have for each countries and we are creating an object for that and that object in degrees our summary one object okay so we'll have for the entire loop we are creating objects and not only that yeah once we have created the object England this is the first three line that we have and the fourth line that we have here is summary one array we contain that object take that out we are sending each time we are creating an object we are sending to the array that we are having somebody want array will have the first object and then summary 1 0 we have to first of it summary 1 1 sorry summary one area one will have the an object somewhere in one array too will have the third object so on you have we are storing all the object into an array and the last thing what we have to do obviously is to have our outputs as we have a input which is the response body in the beginning we're gonna have an output which is going to be s somewhere in one output that's that's the one that I'm creating which will have the entire array so you'll have that area she'll have all the objects inside okay this is the entire script basically to pass the response that we have and then having creating and outputs the reason why we are creating outputs because we want to use that later okay great so here I'm creating the summary one output variable it's an area objects which will have somewhere in one object which is an object and then which will have confirmed cases okay which is in our case here is in time and I will have also recovered cases okay we have created our output variable for the parse step now what we have to do is basically creating an output variable for our action okay so so let's do that so you can output and create output so we are going to just repeat whatever we have written in the past step for the output variables we are going to do exactly the same thing here okay every object summary one object and then confirm cases and then recover cases and we are going to use the data field that we have here on the right side you can see here the summary one object that we have here we're gonna we are going to just drag and drop into this okay okay I've done my dad so you can't exit more and then drag and drop right so we have done pretty much with the script and I have made some mistake here I just need to delete one additional holy brackets that I have here so I deleted that and then now we can test our action so click on test run tests and see the result so this is the result that we should get you

View original source

https://www.youtube.com/watch?v=bMt1w0qYtkg