estately / rets

A pure-ruby library for fetching data from RETS servers
https://github.com/estately/rets
127 stars 94 forks source link

Invalid Query Syntax for valid query #176

Closed Sinetheta closed 8 years ago

Sinetheta commented 8 years ago

Login works great, metadata works great, the following search works great

client.find(:all, {
  search_type: 'Property',
  class: 'Property',
  query: '(ID=*)'
})

but if I try filtering

client.find(:all, {
  search_type: 'Property',
  class: 'Property',
  query: '(LastUpdated=2016-02-18T00:00:00+)',
})

BAM Got error code 20206 (Invalid Query Syntax)

This same query works great over curl. Am I missing something?

dougcole commented 8 years ago

I don't see the problem off hand either. If you pass in a logger with log level debug you can see exactly what URL the rets gem uses, can you compare that to curl and see how they are different?

summera commented 8 years ago

@Sinetheta some rets servers require that you have the ID field in your query.

Have you tried:

client.find(:all, {
  search_type: 'Property',
  class: 'Property',
  query: '(ID=*),(LastUpdated=2016-02-18T00:00:00+)',
})
Sinetheta commented 8 years ago

Thanks for the reply @dougcole, that was my thought as well. The params are making it all the way, exactly in as I would suspect. The only things I can think of are

A) httpclient escapes params differently than curl. I've tried using CGI::escape and URI.encode on the query before passing it in, to no effect. B) There is something unrelated which is different between the requests which is being tolerated when query: '(ID=*)' but not when query: '(LastUpdated=2016-02-18T00:00:00+)' for some reason.

I'll try inspecting the actual network traffic to see if I can spot the difference between the requests.

summera commented 8 years ago

whoops! sorry, missed the part where it works over curl

Sinetheta commented 8 years ago

That's fine @summera, you are right that our provider does claim to require the ID field docs although the curl requests for a query by date only works fine.

Here are the curls I can make https://gist.github.com/Sinetheta/62267fc7ffbf1f148895

Here is the rets client call that works https://github.com/Sinetheta/3pr-rets/blob/master/app/controllers/pages_controller.rb

dougcole commented 8 years ago

@Sinetheta I can't really try that code since I don't have a login to that Mls, but the code looks reasonable. I assume you've tried it with the same query in both ruby and curl?

Sinetheta commented 8 years ago

Well, until I can provide network traffic information then there's not much to say. I can get by making (ID=*) -> parse in ruby -> (ID=number) queries, although I had intended to use LastUpdated instead.

Thanks for the help. I'll let you know if I discover anything new.

Sinetheta commented 8 years ago

So the problem was the +. curl was stripping it but in all my ruby variations I was always including it.

In retrospect, my MLS specifies

Query Syntax: (LastUpdated=RETSDateTime)

but I was focussed mainly on reproducing other people's examples and had unfortunately settled on a query which had an unwanted character :disappointed_relieved:

dougcole commented 8 years ago

good sleuthing, thanks for the update!