logo

NJP

How To - Use the IntegrationHub Inbound REST API Trigger

Import · May 11, 2021 · video

hi my name is jimmy and today i want to show you a quick how-to on using one of the new features that is available in the quebec release and that's called the rest api trigger i think it's a particularly cool feature because it now allows you to take inbound requests to your servicenow instance and fire a flow without needing to write any script right before you had to actually create a scripted rest api write some script to translate your your variables to your flow variables or you had to create a table and have a trigger for flow on that table and do something like that was a little bit unnatural so now we can actually create a rest api trigger on the flow to invoke the flow directly from the external system let's take a look at that so what i'm going to use today is i'm going to use jira as my third party system that's going to and send a request to servicenow and fire the flow why jira i get asked about jira quite a bit so i thought maybe it'd be good to use a system that people have asked about a lot and would resonate with with the audience so to take a look at what jira sends i'm looking at this particular page which is the web hooks page at the atlassian site and it describes basically the the body of what the flow is going to look like right so if i come down here you can see that the um the body generally has this structure json payload and we can come down here for a more concrete example of what some of the data might be so you have the body with an issue inside the issue there's the key and some of the fields right so let's just kind of show how when jira posts this to servicenow how we can extract this in our request and have it available in our flow right so i've already created a workflow so all we need to do in here is we come in here and we add a trigger you can see this is our new trigger right it's an asynchronous rest api trigger and the most important thing to keep in mind is you want to make sure that your your description of what you're creating here and your your trigger matches the requests that's going to come in so i'll show you what i mean by that as we go along but um here we see that we've already created a path or the system's created a path for us we want to make sure that we put the right http method in here in this case jira is going to send us post and we're taking inbound jira and in this case we're just going to create one for updating an issue so when an issue comes in this is when we want or when a an issue is updated in jira is when we're going to fire this particular flow so you can do authentication right i'm going to leave that out just to simplify this a little bit but if you do requires authentication you just set what role you have here and then from your external system when you give it the web hook to the instance you use the standard http colon slash user colon password and then the rest of your fully qualified url to get to your instance all right i'm going to leave that out just to simplify things here the next thing that you'll notice is we have this content request that comes in right this is uh specifically for a post output and here we have the body so what we want to make sure we do here it's really important is to make sure that your body that you describe matches or the the names of the fields match what's in that payload that you're going to get so keep in mind you know make sure that the capitalization is correct so in this case let's just say we want to look at the issue and then we're going to grab the key and and a couple of fields out of this fields body so to start with let's go get um issue so i can say that in my body i have an issue and keep in mind that this is where it's really important to match up the name of the field right the name field here is what what's important that has to match up to the the field that you have in your payload and the label here is just what you're going to end up seeing on the right hand side that you use later on in your your flow so here we have an issue i'm going to change the type here to an object because it is an object and then inside that issue object we have key and we have fields right key is a string fields is an object so let's come back here and we're going to say e and matching my case that's a string and then we have my fields and that's an object so inside my my fields now i have a summary which is a string and a lot of other things as well so you don't have to map every single field that you're going to get only the things that you really need to to use in your your flow as you go along here so all this other stuff users and stuff i don't really need right now so i'm just going to leave it at that so i'm just getting from this payload the key the fields the summary and that's what i'm pulling right and i can also show that let's just say that we want to add a query parameter or a query parameter is going to come across here and let's just say we're going to get the issue id and as a query parameter that's going to be a string here as well okay so i'm going to save that and we're going to show just for simplicity sake right i'm not i'm not trying to build a full integration with with jira doing something in servicenow i just want to show that how you can use this rest api trigger but i'm going to just log the information that's coming in right so once you get to this point you have the information it shows up in the data pill on the right hand side so you have my issue i have my key my field and then the summary in there any of these things can be dragged and dropped and used in any subsequent action that you might do so in this case we're just going to log we're going to say our query param id is this and then we're going to say we have the key and i'm going to go to the body and grab the key from the issue and then we're going to grab the summary [Applause] from the fields and then just to show that we can just upload the whole thing i can just say we want the body and we can just grab the the request body okay so i'm going to save that and i'm going to activate it so you have to activate it before the external system calls that come in are actually going to be processed by this flow so now let me create the web hook on the jira side that's actually going to send the request so let me grab my my instance url and right now i have no web hooks right this is simply just going to the uh the web hooks section in in jira i'm going to create a web hook we're just going to call this the um we're going to put the url here and we're going to go grab the rest of that body and then we're going to add that query parameter so i believe we call that issue id id equals and then um from here i can grab the issue id or the key whatever i need to grab and get it right and then when this is gonna fire on the jira side we're just gonna say whenever an issue is updated all right so it tells me that these are the fields that are available when an issue is updated so lots of other triggers that can be done on the jira site to send outbound web hooks in this case i'm just going to save this and we've activated this so now all i need to do is actually go in here to an actual issue and update it so we'll save that and come back over here and i'll look at my executions and you'll see that we've already had a an inbound jira that fired off i can open that i can see information about that particular request all the stuff that came in and then i can look at my log and see that this is the message that should have gone to my log which has our query param id our key and then the other fields that we actually looked for right this is the summary and then the whole body that we actually just dumped out and in the log that should also show up here and there it is so real quickly we just showed that we're able to create a rest api trigger for flow that lets an external system like jira invoke a flow and service now now that flow can do anything that you want to do with flow given the data that comes in from the rest api trigger so you can do things like update incidents or create projects or update project statuses or even really cool thing is you can have other integrations right so you can have one system come in and update a state of something that then triggers something to happen in servicenow that invokes an integration to another system and starts something there so you can wire together multiple systems in a way that that really wires together your business processes and gives you automation so hopefully that was useful and thanks for your time thanks for watching

View original source

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