How to export instance table data to CSV using REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 10:54 AM
Hello all,
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:
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 = 'tanisha.hudson'
pwd = 'password'
#sysparm_query= import_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^nameSTARTSWITHfb^ORname
# =/dev/mapper/backupvg-backuplv^mount_point!=/backup_rada
# Set the request parameters
url = 'https://capman.service-now.com/nav_to.do?uri=%2Fx_snc_instance_dc_cmdb_ci_file_system_list.do&sysparm_query=import_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^nameSTARTSWITHfb^ORname?CSV'
#url = 'https://capman.service-now.com/ nav_to.do?uri=%2Fx_snc_instance_dc_cmdb_ci_file_system_list.do?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:
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 11:14 AM
Increase the export limt.
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 11:18 AM
Ok thank you Prateek. I was told it is not best to increase the limit. Is the way I am doing this in Python correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 11:21 AM
If you don't want to increase the limit add required filters to extract the data you need or extract the data in chunks.
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 11:28 AM
ok thank you! Would I have to add this query to the end of the url within the platform?
Here is the url below
https://capman.service-now.com/nav_to.do?uri=%2Fx_snc_instance_dc_cmdb_ci_file_system_list.do%3Fsysparm_query%3Dimport_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()%5EEQ%26sysparm_userpref_module%3D7a371c4f1bfb14542569eac42a4bcb4a%26sysparm_clear_stack%3Dtrue