NOWCommunity Live Stream - API Adventures - Inbound Integration Logging

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] good morning good afternoon good evening wherever you are and whenever you are welcome to the community live stream my name is Chuck Tomasi I am from ServiceNow been here for about ten years and it is good to see you again this is the show that takes a look behind the scenes behind the questions behind the answers on the ServiceNow community and brings you the thought process the journey of discovery the reverse engineering that goes into those answers straight out of my head straight to the camera into your head and so you can take those thoughts those process those ideas maybe even the bad ideas the mistakes the boo-boos whatever you want to call them to make you a more effective ServiceNow administrator and developer and with that let's get into it thank you for joining me today again this is May 7th 2020 it is a Thursday and the purple signifies that it is an API Adventures day as you saw from the title screen so we are going to be diving deep before we do that just a quick reminder if you're watching this on YouTube or you want to watch this on youtube you can do that at the URL you see there click like if you find something useful helpful friendly in this video and now will help others click subscribe so you get notifications as I did that says hey it's live we're happening both on Twitch and on YouTube you can do that you get those notifications and there's the twitch link if you're looking for that twitch.tv slash now community and you can get stay up-to-date now the twitch ones only stick around for a couple of weeks but youtube is indefinitely so if you wanted to go back two and a half years ago to the genesis of this you're welcome to do that this is the week of knowledge actually it's more than the week of knowledge see if we had done this originally this would be the last day of the three-day event in Orlando Florida but the party continues as we go on with the knowledge 2020 digital experience there is content this week obviously there is creator con next week and we are going to go on on till the first week of June so there's going to be new content coming out all the time now I know a lot of the sessions are full apologize for that there's a limited capacity on some of them particularly the hands-on workshops because we need to staff that with lab gurus that can assist and we don't have an infinite number of those so we can't just say hey hundred thousand people come on in because we would need something like twenty thousand lab gurus it's not we don't even have that many employees in the entire company yet I'm sure that day is coming soon so that's the reason why it's there if you can't get into them look for them the following week on demand on now learning dot ServiceNow comm we've got those on demand so if you can't get in to say CCW 2786 next week which is building your first app in minutes you can take that the following week which would be what May 18th on now learning on demand at your own pace watch the video pause the video when you want and we will have a way to get you support through the community facts Sasha yecchh who will be watching that particular post will watch for comments and reply to those comments so if you've got a question or you've gone from 2786 to 20 87 87 which is my session for flow designer and you've got questions you post it in the community I'll respond don't worry so good to see you all let's you who've got hanging out this morning we've got swap now good to see you shavoo do I think I'm saying that right apologies the glass I'm not sure if the glasses are blurry my eyes are tired this morning or I just can't see Dhruv is with us bug ish yawn Dhruv always a pleasure send deep Amman thank you for joining thank you for hanging out with us this morning lots of other people loving it so knowledge continues next week is creator con expect to see all of you at your appropriate time zones of course hanging out we'll be doing a fireside chat with Pat Casey that's looking forward to that we've got our hackathon which took place last weekend the judging the finalists the winner will be announced on Wednesday so that is just six short days away from this broadcast which would be the 13th if I do my math correctly we've got that we've got a keynote with Marcus Torres and Chris Haase be showing us some wonderful new stuff we've got hack snacks if you're been to knowledge before you remember the hack zone where you could walk around you see the windmills and the airplanes and the you know the touchy-feely stuff where we show you the art of the possible those have been turned into videos licker bot is back the health club is back we've got a bunch of new ones out there so short three-minute videos like you're walking up and you're talking to these people in real life but it's of course a video we call those hack snacks the hacks own is now the heck snacks hands-on workshops sessions keynotes lots of great stuff creator caught next week make sure you sign up go over to knowledge dot service now calm and I think I have well you can see the light the URL right up there at the top of the screen knowledge dot service now calm is where you want to go to get that good morning Zoe RJ Raja ideal of John Wow everybody's check it in it's wonderful to see you and it's a thrill to be here so looking forward to all of that next week it's gonna be a wonderful time hang out with me there I think we that's the most time I've ever spent on the knowledge slide but it's worth it because it's happening right now and it will be continuing so don't miss out this is a unique opportunity well unique because it's the first time it happened but maybe not the last we we don't know what next year holds in store for us we will be doing a little bit of scripting today I'll be going over some scripting in this exercise somebody asked me the use case for today's workshop involves some JavaScript if you want to learn more I invite you to check out the video series at the link you see at the bottom of the screen bitly /sm - learned SJS take you from basic syntax through script addressed api's which we will be talking about today if you already know scripting from another platform or JavaScript this can help you make that transition quickly you can always go back to any one of these short videos as a reference and I will have today's example in our github repo at the bitly link you see there si - CLS unity livestream is what it stands for and we look at that let's see what's on page 2 page 2 is where we get like oh one thing I forgot to mention about about knowledge is if you're on Twitter even if you're not get a Twitter account and start following the account k and o w3 6 5 fact I'm going to bring that up right now twitter.com and that brings me to my page oh it needs an authentication code which I think it just texted me we won't show that on the screen there it is my code is for the moment that's a nice number get logged into Twitter haven't done that on this machine in a while and if you go and find KN o w3 6 5 it is our knowledge account and they are having a caption contest ok and what I put something on our internal Facebook site and our our team said can we borrow that for our caption contest this is what I sent them today I want I want you to see this I took a picture of the studio before we started recording some creator cons stuff on Tuesday and they posted it on Tuesday said ok that's nice can we share that and say hey caption this somebody must have thought my shirt and tie getting ready for this was funny I think my favorite is Robert Frederick's picture that he doctored up the boat I must have got him because he came with prepare yourselves I should do this this this may be frightening to some people okay I have to if if you're if you're weak of mind or your heart isn't in such good condition you may want to look away at this point what do they say on the news some people may find this seem disturbing well this is what Robert put together and I assure you this is not what look like with my shirt off I'm pretty sure you can tell that just from looking at me with the purple so there's your morning laughs or your evening laughs try not to fall off your chair have a good time with that and let's get back to work shall we now that you've had that fun go follow knowledge 365 it's a lot of fun you'll get more than just news of what's happening and what's going on at Twitter you get fun stuff like that so our use case today that's it the leftover from the last episode our use case today is something that came to me from the community and they asked can we log our REST API and I said what do you mean and I said we have scripted arrests api's and when people hit them we'd like to know where it's coming from and who's doing what and just get some basic logging information so I said that sounds like a great exercise to do for the community live stream so today we'll be talking about logging those inbound rest requests and what I discovered as I was looking through the documentation is a property so I went to dock stud service now.com and I found debug REST API I believe it was debugging rest queries is what it was that's Madrid I don't want Madrid I'm on Orlando it's the same property though so I will filter that debug rest query says there is a property called glide dot rest debug property is true and you get log output so I am going to turn this on I have a simple REST API that I can play with in fact let's go to that now first I'm going to copy this query this debug property statement here and go to my system properties now if you haven't gone to system properties before I have it favorited you can go up here to the upper left and say sis under properties dot lists it's not a module because I don't know why ok it just isn't you can make one real easy go under system definition creative properties ok sis under properties is the table and if I look for a property with that name it is currently not set which means it's going to default to false so let's go and create that notice that this filter is on here's a little quick tip for you if you have anything in the filter anything in this query and click new it will carry into the new record very handy if you're safe filtering 4p1 incidents and you want to create a p1 incident see how that goes very neat this is not going into my rust logger application though this should be going into global so let's switch to global I'll come back to the rest logger application in a minute so close studio so it doesn't get confused and add rest debugging information to the system log let's do something it's even go find this oops true and it is a tree fall see there we go we don't need any of these other properties so we will click Submit we'll ServiceNow you use react.js for portal development in future releases short answer is known yay we are taking our portal development in another direction it's the same technology that workspace is built on it might be react underneath I don't know but we are creating a an abstraction layer based on web components so that we don't get caught by somebody else's technology that's been abandoned angularjs ok we don't want to leave you with technical depth again and in ten years people going well where am I gonna find a COBOL programmer you know that kind of situation so let's we've got that property turned on let's go to the scripted rest api's scripted rest api's and i created one for my CLS application don't remember where it is so let's say the base path contains CLS and i'm sure it'll come up it's a demo alright i'm going to go into my scripted rest api it is very very simple i have a name it's a hello world kind of program you can probably see and I'm just going to log what these parameters are now notice my resource path has a path parameter right up here in the relative path and I can optionally specify other query parameters I'm going to go into the REST API Explorer now I could have gone through the REST API Explorer and found the API and the endpoint and all this kind of stuff but I went this way because I knew where the API was and if I click REST API Explorer here it brings that all up filled in for me which is very very nice so here's a path parameter this is a mandatory one because it's in the path and I'm going to say Chuck but I can also add query parameters say this world here will do K 20 happening now all right and then we'll add another one that says crater con next week simple stuff that we can do with the REST API Explorer with path parameters query parameters this is allowing us to test an API on the platform so if we had a third-party application maybe somebody's writing something in Python clique we could give them a pipeline snippet to help them out or PHP or whatever actually PHP is not on there I am just going to send this to test it it's a gives me Becky 200 okay and no response body but let's go look at the system logs system logs let's spell system logs correctly there's system logs all do we have anything in here or is it hmm think it's not in the log file Taylor I think that's a we might have to download the debug logs let's go and look where does that docs page say it's going to show up when this is true rest processing logged in the session debug log ok those are no fun to read session debug log ah you know what to say but log debug security debug debug Doug where is the session debug log debug log brings up our diva our hour longer logger okay so we could download the log let's run this again there's our session log and let's hit our API again all we really have to do is hit Send I'm blade with this yet so we're all learning here and tada here's a bunch of stuff in the logger got the log is nice once out here in its own thing and again we can do some filtering when clear it we can download it but what it says to me is here is the end point that was hit I'm processing this request it was a get which it was from this host or to this host hard to tell cuz I'm on that host I've got headers I've got that I've got a whole bunch of stuff in your header header header header header I've got the entire header object header header header header hey and processing a lot of good stuff that's a little hard to read though and I can't do any kind of reporting on it so could we put that into a table let's close that and what I built which I will go through with you very quickly is in studio bring me back to my system favorites studio oh thank you drew yes it's called now experience trying to have two conversations at once rest logger I built this real simple at the heart of it we put into our scripted REST API a long statement I said just kind of like a GS log or a GSE info or sometimes I just go through all this into some log that I can report on later so if you were to look at my scripted REST API demo and in the resource you notice really only had one line and it says there we go I throw it the method because I couldn't find out how to get the method off of off of any of the api's and I started by going to it was a developer portal but it might be in here rest message excuse me rest request uh not in there so I think this is where I got it developer dot ServiceNow comm if you watch the new video I like the new video that's cool the search button there and rest request where's our API oh it's a real thing first message v2 we'll start with the message itself so API reference method set endpoint constructor rest message v2 and when you execute it it returns a rest response but what you give it is a rest message where is the rest mass the rest request what I'm after is this peace rest api request that's what I should be looking for nope sorry rest yes sorry the comment is in front rest api request nicely commented by default let's go find one of those rest API response without that leading asterisk that would be a bit of a problem I want to find the methods that are available that is in a learning module we don't want a learning module we want a reference class rest api request sorry for finding this so difficult i will have a link in the show notes for you and it says the body is a rest api request body and when this is this is what I'm getting when it comes in somebody says hey I want something from your system that's a request to service now so the first parameters the request the response is what ServiceNow sends back I'm not sending anything back but I can get header information out of the headers object I can get path parameters out of the path params object so I just take these apart in my script so back in studio I created a few tables one is the actual message says what is the URL the URI that I'm going to keep track of and the method a basic basic stuff maybe it would help if we would I did the cooking show and showed you what this looked like in my rest logger rest logger here's my message and I had a few examples in here where somebody was hitting my endpoint I've got to get to this point to this URI and then I've got some related list because I didn't want to just dump the headers the path parameters and the query parameters into this JSON field that's no fun I suppose I could have used a name value pair field that would have been interesting might have to redo this one with that because that's just stored as JSON and I wanted to do any parsing but what I did is I took these apart so if you wanted to see all of the headers it's in the headers related list cool it was HTTP and then was for this and it's from that that's basically everything that that text log was telling you about but now I've got a way to query it and filter it and put reports on it if I want the query parameters or creator con next week and notice this is in an array for whatever reason the query parameters aren't good path parameters do this the query parameters sends in a raise I don't know why because every query parameter only has one parameter after it I don't even know how you would make an array a list of query parameters for one parameter I guess creator con equals what somewhere there's got to be a way to objectify a query parameter that I haven't learned yet but I noticed that it was coming out this way and if I just said it gets really wacky so what I'll show you what I did in studio so I've got my tables the message path parameters the query parameters these are all real simple it's a reference field a name and a value nothing real spectacular there there's the name there's the value and there's a reference to the message okay so when you see it on the form it looks like say we take our header name value reference very simple so I've got all the parts I know where I want to store this stuff then it comes down to just declaring a script include that you can call from within your script addressed API step one was a made a constants script include so I defined the table names that way when you take this to your instance or you want to re-implement this I will have an update set in our SN - CLS structure under today's date I do have a repo on my personal github site at github slash Chuck Tomasi again I'll include all these links so don't worry about it that you can use if you want to fork that repo and try this but this does have my personal developer instance 6 6 to 3/8 prefix on it so if you wanted to take this and rebuild it and make it your own and just say I just want to copy and paste the script this is the one place where you would come and change those table names that's pretty much it and obviously if you called it from within your rest message you would have to change the prefix there X underscore your company code dot rest longer so this part is the important part to change if you are coming in here making one of your own or adapting mine to yours so keep that in mind this is just like a constants that define section so that when I get to the other script include that has to hold functions or two methods in it let's back that up so we can see this a little better it says you are not in the rest logger or whatever it says I have a log function which creates a new message record doesn't insert on that and then parses out the JSON into its constituent components for those related lists for the header the path per am and the query parameter and I just pass it request headers so what I get out of this as you saw in the scripted REST API method was get comma requests those are the two arguments that I pass in just go chew on them so this chews on them and spits them out log under JSON I found myself doing this three times I went no don't don't write the same function three times it's just a different table name I pass it the table name the glide record I want to attend the parent glide record which is the message glide record and then the object and in here I said wait a minute go through each key in this JSON object each property in the JSON object and add a new record for that okay the key was straightforward it was just some header name or some query parameter or some path parameter but the thing in that key I prefer those query parameters was an object I went oh that's kind of crazy so I just chose to stringify it which is why you see a string that looks like an array it's not really an array it's a representation of an array with one thing in it otherwise just dump out the value which is true for the header and the path parameters so there's your logger I just took a part of those things based on the properties because the request has these things available to them it also has some other methods if I remember right no it doesn't get header if I wanted to get a specific header but I don't get supported response content types what I didn't see is get method the request doesn't tell you what method it is which is unfortunate because I really wanted to not pass in where is it see this nose and our session debug log new it was a get so somewhere it knows that it's a get I just haven't found a property or a method to get the method so instead what I've forced the user to do is when you call the log function you tell it this is a get and you can see right in here where was I was just on the demo API a demo rest resource on here I have to say get and here's your request object called chew on that so simple rest logger to give you some basic properties we can go test it we already did test it sorry and in my messages if I look at the latest one from today it says yeah someone called your truck endpoint and according to the headers you can probably figure out who it was query parameters now you can put that one statement this isn't even in the same scope so you could put that one statement into any scope I did insure when I made the tables the message header and the other tables that the application access allows you to not only read from that table but create so if you were going to do this yourself a couple of things about scope to scope access any scope needs to be able to it needs to be accessible from all application scopes but the caller access needs to be able to create because I'm calling this from the CLS 323 scope and trying to write into the rest logger scope if I hadn't checked that box it would go sorry cross scope Affleck Prosecco applications are denied that's a good thing if you want it that way because by default any scope can read but not every scope can write or delete that kind of thing so I got to make sure to turn that on to okay Dhruv is saying or outbound we have set we have set HDTV log level yes you can do that as well if you're said if you want a debug that I believe that also goes to this session T bar debug log it doesn't create a table entry which would be very difficult if you were unless you were doing a scripted outbound rest that you could log in yourself but if there's something available on the system start there first like turn that property on if it doesn't do if you absolutely have to have some kind of reporting or you want evidence without spelunking through logs then this would be a good way to do it too but be aware that this could potentially create a lot of data you may want to look at log at table rotation so you don't keep these very large log files a long long time think about it if somebody's hitting this HTTP request even once a minute over the course of a year these things can get really really large so be aware of table maintenance as well on something where you're creating large maybe there's a property that would be even a better idea something you might want to look at adding is go create a system property that turns this logging on and off and then when you called log function you just leave that statement in your script includes but it's gonna say go log something and the property says no I won't if it's say false it was turned off you could just return right from here somewhere on line seven eight nine go property says no if the property says yes then I will create the logs now you have a control to turn it on and off in production even better why don't you consider making that enhancement and let me know how that goes there's a challenge for you can we access the current object in the scripted REST API that will be pointed to the scripted REST API that's a great question so you're talking about let me switch applications file switch and in my 323 app I have my sample scripted REST API inbound integration script addressed resource and the so no you can do something like that with inbound email actions let's go look at REST API request was under rest message feet-first API request was scripted I don't know I don't see an object for it and it typically wouldn't be listed as current let's see the REST API requests rest request body response stream his air isn't removed at that you know let's go this way back to Doc's scripted REST API scripted can you give me a use case where you might want that or why you would want that while I'm looking this out why would you want to know suppose you get the method out of there thank you scripted REST API scripted REST API Stan there's a podcast for it on tech bytes scripted a rate URLs have this instance name space version don't forget scripted REST API is also do versioning Rd determines which script box has access to current after I understand that question API resource scripted REST API resource equivalent to arrest endpoint that's where you create the resources which I did that's like you're getting your post for each one of these I've created some REST API script addressed api's that have a dozen different resources on them just because they're all related to the same application of the same function of that application it's something that is passed with glidescope evaluator glidescope evaluator is used for running some text that you would consider a script so I think we're knife look into that I don't think there is a way that I know of at this point but I will track and see if there is a way to get a hold of the rest method itself so with that I think we're at the end appreciate you joining me I hope you learned a little bit about script addressed api's scripting in general again I will have the update set on the github repo for you that you can take this maybe add that property that I suggested and do a little investigation of your own on your scripted REST API is with improved logging til next time which will probably be the 18th because crater con is next week gonna be a little busy for obvious reasons I look forward to seeing you there so let us wrong make sure you get this right don't want to mess things up at the end till next time - keyboard issue I will talk to you later bye now [Music]
Info
Channel: ServiceNow - Now Community
Views: 1,330
Rating: 5 out of 5
Keywords:
Id: H-rQOnXCWFo
Channel Id: undefined
Length: 34min 8sec (2048 seconds)
Published: Thu May 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.