Laurent5
ServiceNow Employee
ServiceNow Employee

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)

find_real_file.png 

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)

find_real_file.png

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. 

find_real_file.png

The following window will appear. 

find_real_file.png

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:

 

find_real_file.png

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

 find_real_file.png

 

 

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

find_real_file.png

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.

 find_real_file.png

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.

 

Comments
Merle
Giga Contributor

Good morning Laurent,

Thank you for this article.

Although I have a question. Is there a way to send the data back to ServiceNow?

Once you have done all your analysis on Jupyter how can we send the data in ServiceNow?

Thanks for your knowledge.

Regards

Juliette

Guilherme Corre
Tera Contributor

You can do the same process, but use the "Create a Record (POST)" section (on the left)

find_real_file.png

Version history
Last update:
‎11-17-2020 08:24 AM
Updated by: