ServiceNow Scripted REST APIs: Part 5 – Scripted REST Service
foreign now that we've taken a look at the vehicles application and the data that will be in the table that we'll use to connect to using our API it's finally time now to start creating our API so the first record that we will need is the scripted rest service or the scripted rest API record itself and this will serve as the foundation for our entire API so let's take a look so in studio we'll go to create a new application file and we'll look for the scripted rest API record so we'll select that we'll give it a name vehicles pressing tab will populate the API ID automatically we've got some protection policies here we won't look at these now but some of them may be familiar to you already if you come from a scripting background in servicenow where you can restrict access to your scripts so let's save that record now let's take a look at a few things here the first thing is the default ACL there scripted rest external default we're not going to change that now we're going to discuss access controls for apis later in this series there's a very important topic so we'll discuss that later under content negotiation by default the system will populate fields for their request and response to accept both Json and XML formats but unless you absolutely need to support XML depending on the client so they're going to be connecting to your API you can just go ahead and populate them both only with Json because that is the standard for rest apis so I'll go ahead and override those defaults and then just to replace the default values there with application slash Json if we go to documentation you can actually provide a link here to your API documentation and I can't stress the importance of having good quality documentation for your API as with anything in software development you really need quality documentation otherwise your users won't know how to connect to the API they won't necessarily know what to expect what parameters they need to provide etc etc so we'll need to provide documentation for that if you want to have a look at a really good example of API documentation go to the developer portal of servicenow and have a look at the API reference there so what we can do here is for this simple demonstration we'll just go ahead and create a new API page a new UI page rather in servicenow so we'll come to UI pages we'll create a new record here just so we've got something to put in that field in our API and we'll give it a name V equals API documentation we don't categorize it we'll just leave it as general we'll provide a short description here and then we'll just go ahead and I'll just paste a very simple HTML jelly XML uh text in here and save it and we'll take a look at it after we provide the role that we need or that you will need to access this UI page so just go ahead here and select our integration role click ok and if we click on the endpoint and try it this is basically what it looks like nothing really dramatic but we've got to start and we've got now something we can put into our API records so we'll come back there and we'll just pop that link straight in there and provide a short description okay so if we have a look a little bit further down we see here we've got some Red Data links the first one is versioning there's a separate video in this series on versioning so we'll discuss that then if we scroll a little bit further down we've got a few different tabs here the first one is resources which we're going to discuss in the next video okay the resource will be the HTTP methods that we'll use to get data create data delete data Etc you can provide some request headers here and you can also provide some query parameters but we'll get to that later as well when we discuss the get method okay there are different ways to provide parameters to the API one of them is in the query itself and one is in the path but we'll talk about those once we actually start creating our resources so that's it we'll go ahead and update that and we have now created the foundation record for our scripted rest API and that's it we have now created the foundation record for our scripted rest API in the next video we'll discuss resources
https://www.youtube.com/watch?v=NtCPwCgOj1Q