logo

NJP

Accessing ServiceNow from a Jupyter Notebook

Import · Nov 17, 2020 · article

If like me you like working in Jupyter Notebooks with Python and wish you could access your ServiceNow data, the little tip below might interest you.

You can easily create a Rest call using Python from your ServiceNow instance. For that, you need to navigate to the Api Explorer screen (System Web Services -> Rest API Explorer)

image

Next you need to select the Table API.

Then, select a table, for example Incident, and the fields you want and other selection criteria. In our example, we are interested in Incidents descriptions and the location coordinates (latitude and longitude). A little bit of dot.walking (location.latitude, location.longitude) is required for the latter. You also need the maximum number of records to be returned (1 by default but can be increased)

image

Then, all you have to do is click on the Python link at the bottom of the page and it will generate the code for you.

image

The following window will appear.

image

Cut and paste this code into a Notebook, change the default user id and passwords in the code sample (best to create a specific account for your REST access) and Voila!

Having accessed your data from your Notebook, you can also import Pandas and add your data to a data frame, parsing ‘result’ from the generated json response:

image

We can now view our data in a nice data frame:

image

With our data now in a data frame allows us all sort of cool data manipulation and access to libraries like matplotlib:

image

Since we extracted the coordinates, we could display our data on a map using Geopandas as an example below.

Here we are displaying our incidents in the US with a different color and marker depending on the number of reassignments.

image

Python is one of the most popular languages and certainly at the top of the list for data science, with a plethora of libraries available for data analysis and visualisation. Using Rest api calls to easily access your ServiceNow data from a Notebook using Python opens up many exciting possibilities.

View original source

https://www.servicenow.com/community/now-platform-articles/accessing-servicenow-from-a-jupyter-notebook/ta-p/2321372