REST API + Python: How do I read the data the python code pulls from ServiceNow?

amn
Mega Contributor

I need to pull data from ServiceNow with Python and write it into an external database. The data is returned in this format:

{'result': [{'sys_id': '1c741bd70b2322007518478d83673af3', 'number': 'INC0000060', 'short_description': 'Unable to connect to email', 'assignment_group': {'link': 'https://dev12604.service-now.com/api/now/table/sys_user_group/287ebd7da9fe198100f92cc8d1d2154e', 'value': '287ebd7da9fe198100f92cc8d1d2154e'}}]}

How can I get that data into an array of objects that can be looped over for processing?

1 ACCEPTED SOLUTION

amn
Mega Contributor

figured it out. I'm not familiar with python so this took longer than it should have...

print(data['result'][0])

View solution in original post

6 REPLIES 6

This is really helpful and Thanks! Now I am very new to Python and API Development (I come from traditional ETL-DataStage background so apologies in advance)!

 

How do I create a CSV out of this JSON response for multiple rows?

 

Could you please post a code snippet for this?

Ranjith G S
Tera Contributor

const data = {'result': [{'sys_id': '1c741bd70b2322007518478d83673af3', 'number': 'INC0000060', 'short_description': 'Unable to connect to email', 'assignment_group': {'link': 'https://dev12604.service-now.com/api/now/table/sys_user_group/287ebd7da9fe198100f92cc8d1d2154e', 'value': '287ebd7da9fe198100f92cc8d1d2154e'}}]};

const arrayOfObjects = JSON.parse(data).result;

for (const object of arrayOfObjects) {
console.log(object);
// Do something with the object
}