AnsweredAssumed Answered

Hosted FS query (date column)

Question asked by jamesfreddyc on May 7, 2018
Latest reply on May 7, 2018 by jamesfreddyc

I'm attempting to query a hosted feature service on a date column and getting error code 400 "where parameter is invalid".  However, if I copy/paste the printed query url into a browser, it returns the correct result! 

 

I've tried different permutations of this with no success:

 

 
where = "EditDate>=date'{}'".format(inputDate)
where = "EditDate>=date {}".format(inputDate)
where = "EditDate>='{}'".format(inputDate)
where = "EditDate>={}".format(inputDate)

 

(also: the same exact code below with a different where clause on a text column does not error and returns correct result).

 

Can you spot the issue?

 

def checkForUpdatedFS(taburl, uname, pword, inputDate):
    if taburl != '':
            try:
                tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
                params = {'f': 'pjson', 'username': uname, 'password': pword, 'referer': 'http://www.arcgis.com'}
                reqp = urllib2.Request(tokenURL, urllib.urlencode(params))
                responsep = urllib2.urlopen(reqp)
                datap = json.load(responsep)
                token = datap['token']
            except:
                token = ''
   
    where = "EditDate>=date'{}'".format(inputDate) #query on a date column
    #where = "field_4='{}'".format("WO4819949116") #query on a text column
    query = "/query?where={}&outFields={}&returnGeometry=true&f=pjson&token={}".format(where, '*', token)
    queryfsURL = taburl + query
    print queryfsURL #use this to paste into a browser to see result

    greq = urllib2.Request(queryfsURL)
    gresp = urllib2.urlopen(greq)
    gdata = json.load(gresp)
    print gdata #print response

    rCount = (gdata['features'])
    if len(rCount) > 0:
        print 'New Survey added to {}'.format(taburl)
        return len(rCount)

Outcomes