
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-17-2020 08:24 AM
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)
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)
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.
The following window will appear.
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:
We can now view our data in a nice data frame:
With our data now in a data frame allows us all sort of cool data manipulation and access to libraries like matplotlib:
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.
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.
- 2,384 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You can do the same process, but use the "Create a Record (POST)" section (on the left)