Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

pandas - Exporting data as CSV file from ServiceNow instance using Python

I have some data in an instance that I would like to export to a CSV file using Python and the REST API. I wish to use REST, because there are some rows missing when emailed as a .CSV file. The query gives me 12,000 rows, however, the file that is emailed to me only contains 10,001 rows.

Here is the data I wish to export to CSV:

enter image description here

I have added a filter, and it is only about 12,000 rows that I wish to export. This is what I am doing in Python:

user = 'user'
pwd = 'password'





# Set the request parameters
url = 'https://instancename.service-now.com/nav_to.do?uri=%2Fx_snc_instance_dc_test_ci_test_system_list.do&sysparm_query=import_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^nameSTARTSWITHfb^ORname?CSV'



# Eg. User name="username", Password="password" for this code sample.

requests.get('https://api.github.com/user', auth=('user', 'pwd'))




# Do the HTTP request
response = requests.get(url, auth=(user, pwd))


# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:', response.content)
    exit()
    
    
    
# Parse JSON response body 
print(response.content)

However, the output appears to be html and CSS:

enter image description here

I am still troubleshooting this, and would like to know if my above code is correct, or what needs to be tweaked to have the data exported in a .csv data-frame format and to a csv file. Any suggestions are appreciated. Thank you

question from:https://stackoverflow.com/questions/65943924/exporting-data-as-csv-file-from-servicenow-instance-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

ServiceNow will limit exports to 10,000 records by default for performance reasons.

Try adding &sysparm_limit=20000 to your URL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...