• 0
Steve E

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

Question

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?

 

Edited by Steve E

Share this post


Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 0

@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!

Share this post


Link to post
Share on other sites
  • 0

@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?

Share this post


Link to post
Share on other sites
  • 0

@Sarah Terry

 

https://companyname.logicmonitor.com/santaba/rest/device/devices?filter=updatedOn>1504905976 is the exact URL/URI that I use when making a call (Which returns 400 - Bad Request)

 

The request is successful (200 - OK) when I simply change the filter from '>' to '!~' for example. https://companyname.logicmonitor.com/santaba/rest/device/devices?filter=UpdatedOn!~1504905976

Share this post


Link to post
Share on other sites
  • 0

@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

 

Share this post


Link to post
Share on other sites
  • 0

@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!

Edited by Steve E

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now