How To - Build a Custom SecOps Integration with the Rest API Explorer
hello everyone this is Muhammad Nasir and I'm a senior solution consultant here at servicenow specializing in security operations this is my series dashing through the workflow and I'm going to be taking the month of December where we are going to be learning a bunch of different features that are within the service now uh platform and how we can utilize them in our operations I'm starting the series strong with the how to integrate with servicenow using our rest API Explorer I wanted to set this as an example of how we can utilize this feature so just for education purposes I'm actually going to go ahead and build an integration that allows us to copy incidents that are created on one servicenow instance onto another servicenow instance now this shouldn't be much of a difference when we are trying to build that and same integration between a servicenow instance and another web application the reason for that is that servicenow makes it easier for you by basically providing a bunch of different code samples which can be utilized for different web applications for today's purpose we're going to focus on servicenow script but just to show you or give you an idea we also support CWC URL python Ruby JavaScript Pearl and Powershell now I'm gonna walk you through the rest API Explorer page and some of the information that you'll find on it starting with the namespace namespace basically allow us to focus our integration on a specified uh scope application within the platform as you can see these are some of the different scope application since this is just a general tutorial I'm gonna just keep it on the now then we can specify which API name that we are looking to do either tablesp API syntax editor UI Glide record API it really depends on which table API that you want to reference I'm also keeping that it's at table API and then we can indicate which API version we want to go with this is going to be the partial endpoint for the selected API and this is where we are able to look at the share link look at the API documents or even access the API analytics dashboard now just to give you an example I'm going to go ahead and actually retrieve a record it looks like it's already on the get function and then I'm gonna specify which table I want to get that record from since I just want to test out if this is an accurate function and if it is working properly I'm just gonna go ahead and look for the incident table I can specify the different parameters or the query parameters that is going to be used to call that specific record I can either look for one or pull in 10 at a time I'm just going to keep it a 1. after that we're gonna specify what are the fields that we are looking to pull from that record as you can see here I have the option to choose these fields right from the available ones I'm just going to get to when it was updated the state maybe the priority and finally let's do the overview click on Save so these are the fields that are going to be pulled we can scroll down and see the status code 200 okay that means that we have we were successful and that we were able to actually get that record now let's go ahead and go over an example of creating a record through the post request we're gonna specify which table we want to create the record on I'm keeping it simple throughout this entire Workshop so I'm gonna Focus everything on the incident table so I'm just typing out incident but we can see here this is an example of the different tables that we can create to and get information from so is it the regular incident table is it in the case of secops the DLP incident table is it the security incident table you get to decide which table you really want to pull that or create that information on keeping it simple again we are going to focus on the incident now if we scroll down we are going to see the request buddy which basically tells us all of the different information that we are going to be creating on the actual record uh again I'm keeping the request format and the response format AS application Json because we are working on two servicenow instances now within the Builder I can specify which are the fields that I want to create so I'm going to add a couple here and then let's go ahead and fill them out starting with maybe we want to add the description we can see that the uh value here is going to be a string I'm going to say test and then maybe specify the priority and I'm going to say it's a priority three maybe the contact type let's say email now obviously we can change that maybe if we want to say or if in the case if we are building an actual integration we can have the contact type as the name of the integration that we are building let's look for urgency and let's keep this at a one and then finally we can add the impact let's also say that this is a two now we can see everything that we're doing here is being translated down here in a code format we'll see why this is super handy in a second just double checking every information here is accurate now let's go ahead and click on send just confirming that we are creating a record here click on OK so the status code now is 201 created that means that we were successful creating This Record now since we are interacting with again two servicenow instances I'm going to be looking at the code sample for the servicenow script so if I click on it this basically is going to show me how according to the API we are supposed to request or in this case create a record I'm gonna go ahead and copy select the snippet and control and copy now one thing I wanted to um draw your attention to is the fact that the VAR username and the VAR password every time you create this you would actually have to modify that based on the actual integration a username and password now I don't want to give the other tool for access to this instance or in this case the other instance full access to this instance so I'm gonna go ahead and actually show you how we can create what we call a service account so if I look for users I am going to be able to create a specific user that is going to only be allowed to access information specific to this integration so we can go ahead and click on new and then we can say user ID in this case let's just say example integration user we can add in a username sorry a first name a last name a title and I'm gonna make sure that we have this turned on indicating that this is only going to be accessible through the web service save and just to make sure that this actually has the uh appropriate access right to be able to create delete or get information from different records I'm going to give it an idle access click save and then we can set a password let's go ahead and actually generate one I'll copy that save password and I'll copy that into a text note so now when we want to actually interact with this code or use this code to build the integration we can substitute the username with example integration user and the password we have just created now let's set up the stage and go into the script background there's an s I'll open that in a new tab and then we'll take the code that we've copied make sure that you change the username to the username that we have created making this easier and the password is going to be the password that we've copied click on run script this means that we've already completed the scope Global script which means that we were able to create the record now we can jump onto the other instance where we're actually going to be creating the rule that once triggered is going to call the API that we've just created and allow us to create the connection that we wanted to do so um in this other instance I'm gonna go ahead and navigate to the business rules business rules that should be under system definition perfect just give it give it a couple of seconds to load click on new and then name this new business rule I'll keep it simple and say create incident from another service now the table that we want this our business rule to be triggered on is going to be the incident table now this also or this feature could also be utilized in case of we have been using itsm to create security incidents and we've upgraded into the secop solution we can utilize this actually to move incidents from regular table incidents to the security incident table based on summary of the criteria make sure Advance is active oh when do we want this to be actually run let's say after and then we are inserting indeed now we can go ahead and copy the code that we have created here making sure that we change the username and password to the integration uh service account now we can also specify some of the conditions on when to have that API call run so we can either specify that we want this to run based on maybe a date of an incident uh maybe on some of the conditions that we need to have satisfied to initiate that connection now in the case of your integration then we can say that maybe every time we receive an incident or every time a new incident created based on a specific criteria or in a specific assignment group then go ahead and create that record now after we are done with everything that we want to indicate we can go ahead and submit and now we know that every time we create an incident on this instance it's going to be automatically created on the other instance now let's move on to the incident table let's look for the incident that we have created open this up and as you can see all of the different information that we filled in while we were creating the rest API from the rest API Explorer were translated into the incident here and later on we can do things that are very basic to the servicenow platform like for example if we want to create a new channel we can actually change the label add in a specific choice based on if maybe this Choice only applicable to the API that we have created but these are all Native service now functions that you can learn more about on the documentation site thank you everyone for being part of today's episode of Dashing it through the workflow again my name is Mohammed Naser and I hope I provide you with more value through the rest of the series if you have more questions about the rest API Explorer please do reach out to your servicenow expert or please do check our servicenow documentation site and the community site which has a lot of different articles that walk you through the different steps of the rest API Explorer function please let me know if there are any other features that you might be interested in seeing more information about and I look forward to seeing you on future episodes thanks everyone
https://www.youtube.com/watch?v=2xsorIqqqiY