logo

NJP

#REST API explorer- Use of code Samples- Inbound Request

Import · Dec 06, 2019 · video

hello everyone so in this video what we are going to look at is to how to retrieve some data from ServiceNow tables so here I have an HTML page that I have created and I have two input fields and one search product so what I want is I'm gonna enter here to example I will tutor is one of the existing user that we have in ourselves now insolence and when I'm going to click on search I would like to have some information such as email ID phone number location perhaps the manager or escalation point or any type of information that we have in their user record okay so how we can make them make this thing possible how we can display this information so that's what we are going to see so the first thing we are going to look at is the REST API Explorer so in my personal local instance I'm gonna type REST API so under system web services you do have REST API Explorer so basically this is where you can find all different API is that which is which were created for service now okay so here make sure they select namespace now and under API name you can see oh the list of the API is available so this is in the same way for example you have other platforms such as Facebook LinkedIn or any other application they have the API but if you want to interact with that application get some data or post some data to whatever the operation that you want you're gonna use their API right so in the same way you're going to use the API created by ServiceNow it is available here and we can send a request to that API now to get some data okay so in our case is going to be the table API and I'm gonna select here so this is the place where actually you can prepare your request so you can specify one of the query parameters so on so the first thing what we are going to mention here is the user table so table name is going to be the user table so I'm gonna type sis user so here we have the user table so this one is selected and you do have here some query parameters already created for us but here there are no values but what we can specify some values for example for sis form fields this one is going to allow us to see some specific information okay so let's say I want to see only the email ID the phone number this kind of thing or some other feature I can actually hear mention what feel that I want to see so I'm gonna select your user ID and then email so I'm going to keep it simple because I don't want to select manager or department location on the white phone number because these information are not available in the developer instance because most of the cars are pretty empty so I'm gonna select user ID and email these are like we can get some information something like that and add to query parameters the first one is all going to be our first name the second one is going to be our last name because these are the two parameters that be query parameters that we are going to mean we are going to send a request that we are going to mention right so the first one is going to be the first first name so I'm entering here the database name of that column so we do have our usual table you see people have different colors like all the columns that we saw and I mean they're clicking around the fields here when we are selecting and we do specify here one column that I want to have as a query parameter so I'm mentioning here the database name of that column so it's going to be first name and the database name first underscore name so same logic for the last minute so that here I put some value here okay so I'm gonna send the request and see what's gonna happen so I have the response the response code is 200 ok so it means that this is successful I have a response body so result username I have appletalk teacher email abled our tutor at example.com so now at this point they have made a query we get the answer we are able to see it so we want to do exactly the same thing in our picture so how we can do that it's very simple you do have here for example code samples and we have two JavaScript code here so all you need to do is to take this code use this color in order to send that request but it's not that more simple we have to little bit change our code modify some information and we want to display our data right so we're gonna use some other languages for example we're gonna use angularjs framework in order to display the data in here so that's the thing we are going to do first once we are ready be done we're gonna take this code modified a little bit add some more lines and then test if this thing is going to work or not okay so let's prepare the first part of the code so here I have the HTML page for this layout so basically let's say put feels and then and then the search button so what I'm going to do is to create some languages directives so the first directive is going to be ng app okay so I'm going to call it user detail the second directive is going to be ng-controller directive whatever the value that we're gonna have in our input field we're gonna have it in our variable called first name okay so I'm gonna have the same thing for the last name so I'm going to put it right here then just delete this one okay and in here I'm gonna create ng click so whenever I'm going to click on the button it should trigger a specific function so I'm going to call it get detail okay so it's pretty much done so we have our directives created so what we have to do now is let's say start right over to JavaScript function so here I have created already a file which is not which is empty carries the data J's file and I create on a specific folder so in your HTML page if you do the same thing make sure that you have the source link here so you should have the script tag mentioning where you can find this file and also as we are going to use the angular yes we should include as well the library and make sure that you have on the top not somewhere here or here or here we're not going to work and you do not get any error message so it won't be able to find why it's not working so it make sure that I put this line on the top so that's the thing so let's start to write create our module so it's going to be angular module our module is going to be following on the first line is going to but we are going to create copy okay okay so my code will come inside here write the code that we have in our here will come in here okay so now what we are going to do is to create the function okay the function get user detail so that's the one that where we are going should be triggered when we are going to click on the button okay get user detail so now to do that I'm very good get that's it so I just make this one proper okay all right so inside here we're gonna have our function so I mean just sir our script I just copy the entire script here so I don't need this one time and I don't save that one okay so here I have to also add one more line when we are going to send a request I noticed that if you have some sort of issues there's some kind of proxy which is blocking the request so not to work around we need to add the following you're just in the beginning of tower URL that we have already so I'm gonna just add that in the beginning so we don't you're not going to have that sort of problem and in here I'm gonna mention what is my user ID so I mean the user name and user password so you should enter yours let's say and in here I'm going to mention instead of a ball I should have something else so I'm gonna have a variable which will have the value of the that we are putting in the input field not to do that double quotation plus plus and then inside of I mention the variable is going to be first name same thing for the last name right here okay this one is done great so all we need to do is to write our code in here and before even doing that what I'm going to do is just make an alert to see if it is working or not if I don't have any problem I'm going to just make an Al hello right here so to make sure if I click on the function is going to say hello okay I'm gonna have another okay so let's go here I'm gonna move on and then start write our code here so now what we're going to do is we do have a response and I create a node here alert this response okay so this is the syntax where we can you can use this where we have the response so I'm gonna other to this one to see if I'm going to get a response or not so I'm gonna have here some values so I could have the response so username ability to email ability to example.com so I do have the other so what is the goal now is to bring their information into our page right to display not just to have another okay so that's what we are going to do at this level we're gonna write some more lines of code the first thing I'm going to create a variable I'm gonna call it adds to be equal to because I'm gonna power some so the result that we have in our let's say in our there is a very so we have to parse it so I'm gonna pass it going to be this response once we have passed that response we're gonna store it in a specific variable so it's going to be for example dot ID then we have the hands and worst user underscore name okay this was our either ID and then [Music] email okay so these are the variables that I have credit so I'm gonna create some more tags in my HTML page so we can see them so I'm going to create two motives the first day is going to be I'm going to create a class I'm gonna box E because I have already created some design for the char so I'm gonna hear mention here what we call right here an expression an expression which is going to allow us to show the data that we have in this variable ID so I'm gonna do the same thing for email so I just copy that one and putting half here because I've already another div style that I have made for that specific okay so that's it so we do have our expression created and one more thing that I should add here is because as we are sending a request it's there is a kind of Shiva green sari between on angularjs and yeah on the code that we have written here it's not displaying lately the data you should actually click twice now to display that in order to work around you need to write the following code so we're gonna push these values to be visible when we are making when we are writing this this line of code so I don't need this one alert let's see now if we is going to bring us some data or not so I should see there is name email in my page just refresh Fred okay I should see it but I don't have some sort of layout issue but I'm able to see that so probably I didn't do something properly yes because it's not F Fred okay so as you can see here I can I'm able to see the email and also the user ID so that's how we can bring some information from ServiceNow table using making a rest call and to the API Explorer and then getting the data parse it make it visible in our page thanks for watching hope you enjoy bye

View original source

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