How to create Scripted REST API in ServiceNow | 4MV4D | S01L08

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in order to subscribe to my channel please click here or click here please share comment and like my videos and channel hey guys this is god of welcome to ServiceNow four-minute video for developers in this lesson you will learn how to build a scripted REST API this is my personal developer instance in order to create a scripted REST API you have to type a scripted rest and you will see under system web services we have a scripted REST API if you will click here you will see the list of scripted REST API is which are already there in the base line of the system that is out of the box now before I create a scripted REST API I just want to show you one thing so let's go to REST API Explorer if I open REST API Explorer or maybe let's open it in new tab this is REST API Explorer now I have the stable API that means which you can provide to your consumer to get the data for a specific table so for example here I select incident I select incident and then I can just click on send it will return all the fields you have on incident table similarly if I click on this one this method that is retrieve just a record here I can put the table and then I have to give the society so that I can fetch the data for particular racket so in that case I will look for incident I will open this in a new tab let's see if we have like this this particular incident I will copy the society I will go to the REST API Explorer paste it and click on send now this is the API which normally a developer gives to the consumer so that they can fetch the data but it might happen that there might be some tables where you want to restrict you don't want to expose all the fields you have on a particular table and you don't want to use this table API so in that case you can definitely use a scripted REST API they are other ways as well but if you just want user that they just fetch the data in that case you can use a scripted web service REST API so as of now you can see it is returning all the fields of incident table now how exactly I can limit this so let's go to a scripted rest API so I will click on a scripted REST API click on new button it will open up a new form I have the form right here and he will I will mention incident rest demo I will press tab you will see it automatically shows the API ID and here I have API namespace which is also automatically being selected I will save this after saving this you will see the base api path is already here that is slash api the api namespace and the rest api which we are creating the name of that particular API with the ID but i have to create the resources and the bottom you can see here we have resources so you can create your first resource so let's take an example you want to just fetch the data from incident table and consumer will send the society so in that case I will do get I&C and I will keep selecting get method here in relative path I can give get I NC / and I will give a variable which will be sent by consumer and that'll be assists ID and here's the scripting part so I have to do scripting because as of now it doesn't know how exactly it reconnect or Fez the data from incident table so in that case first I will declare a variable that will be like just sis ID equal to because I want to first fetch because consumer has to put that society in the URL endpoint and in the base path in the relative path which we have created so what we will do we will click on just request dot when you will do the request dot it will show you all the methods which you can use with request so we have like path param here I can do dot and I can use the same variable which we are using at the top here Society and I can just put semicolon then I can do where gr equal to new flight record I can put incident table and you can put any table you want but I can do gr dot you can create your script as per your requirement so I will do G wrote query here I can put society this is the society of that record on incident table I will do comma now here I will use the variable which I have used at the top and this is the variable I have just created and I will do gr dot query semicolon now I will do before that I have to do F and I will do gr dot next that's it and now I will maybe first I have to create the request body how I will do that I will do where body equal to I'll put in in the JSON format that's what if we have to create this body call to death and then you can do body dot you can do number equal to you know these are the variable which you can create by yourself yes in that case body dot number equal to you can give gr dot number colon and then you can give body dot short description short description equal to gr dot short underscore short description and then I can do response dot set body and here I can put the body variable which we have created and semicolon again and that's it so you can understand the script here at first we are fetching the value from the request body which will be sent by the consumer and then we are returning the response in this format so in that case I will save this now one of the important feature and one of the best feature I can say about the script addressed web service is also that you can also use REST API Explorer so you will see this option under every resource you will create for any rest a scripted REST API you just need to click on this once you will click on this it will automatically open that particular endpoint here you can see get this the one you have created it is not table API it has also selected the name right here API name you just need to give the Society so what you can do we can just pull the same society paste it right here and try to send it if I send this you will see it has only returned two fields number and short description even you are hitting incident table so this is the utilisation of a scripted REST API that you can design your own api's as for the customer requirement you don't have to expose everything whatever you have in ServiceNow you can you can you can like definitely customize your REST API ask for the different requirements may be customer needs may be different type of records may be incident change problem with just one API you can also develop that you can create and REST API maybe that's just maybe that directly querying ITSM tables which will all end for example if i have get i NC maybe you can create another resource that we cut PRB that is get problem in that case you can add multiple so with just one kind of api custom API and you can limit the fields you want to expose to the consumer so that's how you can create custom and Sceptile rest api thanks for watching my video have a great day
Info
Channel: SAASWITHSERVICENOW
Views: 9,175
Rating: 5 out of 5
Keywords: servicenowapi, servicenow, rest, restexplorer, how to create incident with rest, rest in servicenow, servicenow rest, servicenowrest, integration, servicenow integration, incident management, incident, What Is ServiceNow, what is servicenow platform, servicenow training, servicenow administrator training, servicenow tutorial, servicenow tutorial for beginners, what is servicenow software, what is servicenow administrator, servicenow basics, What is Cloud, introduction to servicenow
Id: 48aBJqdC6xI
Channel Id: undefined
Length: 10min 19sec (619 seconds)
Published: Tue Feb 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.