Use sysparm_query=active=true^state!=6 in requests.get

Skytek65
Kilo Explorer

Right now this is my working code 

import requests
import json

# Set the request parameters
url = 'https://instance.service-now.com/api/now/table/incident'

# Eg. User name="admin", Password="admin" for this code sample.
user = 'user'
pwd = 'password'

# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}

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

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

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)

My question is how do I set a filter on the data that comes back using these conditions sysparm_query=active=true^state!=6

Im using python to retrieve the data, any help would be much appreciated. 

 

 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

you can add filter directly to call so all results will be filtered.

url = 'https://instance.service-now.com/api/now/table/incident?sysparm_query=active%3Dtrue%5Estate!%3D6

 

Doc - https://developer.servicenow.com/app.do#!/rest_api_doc?v=jakarta&id=r_TableAPI-GET

View solution in original post

1 REPLY 1

Mike Patel
Tera Sage

you can add filter directly to call so all results will be filtered.

url = 'https://instance.service-now.com/api/now/table/incident?sysparm_query=active%3Dtrue%5Estate!%3D6

 

Doc - https://developer.servicenow.com/app.do#!/rest_api_doc?v=jakarta&id=r_TableAPI-GET