Forum Discussion

Steve_E's avatar
7 years ago

[REST API] Filtering on "updatedOn" using the ">" operator returns 400 - Bad Request

Hello!

 

We are trying to filter results based on the "updatedOn" property using the ">" operator. However, the request status will always return a 400 - Bad Request.

We have used other operators that are successful, such as "!~"

 

Example of a successful call (200 - OK):

https://companyname.logicmonitor.com/santaba/rest/device/devices?filter=updatedOn!~1504905976

 

Example of a unsuccessful call (400 - Bad Request):

https://companyname.logicmonitor.com/santaba/rest/device/devices?filter=updatedOn>1504905976

 

Am I doing anything wrong? Is this filter possible?

 

  • @Sarah Terry @Steve E

    Yep, it was URL encoding for me in the case of PHP.  Weirdly though ASP.NET wasn't working but it now even though I haven't modified the code to URL encode.

  • @Sarah Terry

     

    Just tested your script. It worked, however it seems the difference is how the two programming languages (Mine being Salesforces Apex) encodes the URL. Python seems to automatically encode the URL, on send the '>' is converted to '%3E' which makes sense. Apex does not automatically do this. When I replaced the '>' with '%3E' in my code, it worked. That might be the issue @Mosh is having as well. Might be worth noting the encoded URL characters in the filter sections of the knowledge articles... Thank you for your help!

  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    @Mosh @Steve E 

    Here's the request I'm making, which is successful (I've included the full python script):

    #!/bin/env python
    
    import requests
    import json
    import hashlib
    import base64
    import time
    import hmac
    
    #Account Info
    AccessId ='ACCESS_ID'
    AccessKey ='ACCESS_KEY'
    Company = 'COMPANY_NAME'
    
    #Request Info
    httpVerb ='GET'
    resourcePath = '/device/devices'
    queryParams = '?filter=updatedOn>1477952627'
    data=''
    
    #Construct URL 
    url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams
    
    #Get current time in milliseconds
    epoch = str(int(time.time() * 1000))
    
    #Concatenate Request details
    requestVars = httpVerb + epoch + data + resourcePath
    
    #Construct signature
    signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())
    
    #Construct headers
    auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
    headers = {'Content-Type':'application/json','Authorization':auth}
    
    #Make request
    response = requests.get(url, data=data, headers=headers)
    
    #Print status and body of response
    print 'Response Status:',response.status_code
    print 'Response Body:',response.content

     

  • @Sarah Terry

    If I make a REST call to /device/devices?filter=updatedOn>1504905976 I still get HTTP response code 400.  Sarah, can you share the test REST URI you are using that is working for you?

  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    @Steve E @Mosh

    Can you provide more detail re the requests you're making?  We've been unable to replicate the issue, and are finding that using the < and > operators to filter on updatedOn for the devices resources is working. 

    Thanks!

  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    Hi @Mosh and @Steve E,

    Thanks for pointing this out - you should be able to filter on the updatedOn field with operators such as < and >.  We'll get this fixed.

    Thanks,
    Sarah