Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get last 15 mins of created incident using snow API using Python

MohammadArI
Mega Contributor

I am using the below code to get the list of incident created in last 15 mins but its giving all the incident (10000), created in last 6 month, any help will be appreciated.

import requests

def get_recent_incidents(instance_url, username, password😞
    api_endpoint = f"{instance_url}/api/now/table/incident?   sysparm_query=sys_created_onRELATIVELE%40minute%40ago%4015"
    response = requests.get(api_endpoint, auth=(username, password))
    if response.status_code == 200:
        return response.json()['result']
    else:
        print(f"Error fetching incidents: {response.text}")
        return []
username = "admin"
password = "admin"
recent_incidents = get_recent_incidents(instance_url, username, password)
print(recent_incidents)
0 REPLIES 0