Programmatically Triggering Export Sets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 04:43 PM - edited 01-25-2024 10:32 AM
Hello everyone,
I'm currently working on exporting a large number of tables (2500+), and I'm looking for a more efficient approach. This is a one-time data dump, and I've already set up the export sets and definitions. My goal is to trigger and monitor the exports programmatically, preferably using a curl command.
Specifically, I want to export the tables one at a time and ensure that the export monitor finishes before triggering the next one. I attempted to initiate a scheduled export with the code below, but encountered a "POST method not supported for API" error.
#!/bin/bash
# Set ServiceNow instance details
source external_vars.sh
# Query parameters
table="scheduled_data_export"
sys_id="b43407d632d84dc9a4976b9372162329"
# Create a GlideRecord instance using the ServiceNow REST API
response=$(curl -s --user "$username:$password" \
"$instance/api/now/table/$table" \
-H "Accept: application/json" \
-G --data-urlencode "sysparm_query=sys_id=$sys_id")
# Check if a record is found
if [ "$(echo "$response" | jq -r '.result | length')" -gt 0 ]; then
# Extract sys_id from the response
record_sys_id=$(echo "$response" | jq -r '.result[0].sys_id')
# Execute the scheduled job in scoped app using the ServiceNow REST API
curl -X POST --user "$username:$password" \
"$instance/now/table/$table/$record_sys_id" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
--data '{"action":"execute-now"}'
fi
In summary, I need to:
- Programmatically initiate an export set/scheduled export using curl or a similar command.
- Check the status of the ongoing export set/scheduled export.
- Trigger the next export set/scheduled export once the current one is completed.
Thanks,
Ben