Using the QueryBuilderΒΆ

Example showing how the QueryBuilder can be used to construct a query using the Python datetime library.

import pysnow
from datetime import datetime, timedelta

# Create client object
c = pysnow.Client(instance='myinstance', user='myusername', password='mypassword')

today =
sixty_days_ago = today - timedelta(days=60)

# Query incident records with number starting with 'INC0123', created between 60 days ago and today.
qb = (
    .field('sys_created_on').between(sixty_days_ago, today)

incident = c.resource(api_path='/table/incident')

response = incident.get(query=qb)

# Iterate over the matching records and print out number
for record in response.all():