taylorbrooks / closeio

A Ruby wrapper for the Close.io API
http://developer.close.com
MIT License
45 stars 57 forks source link

list_leads email query returning 0 results #51

Closed mgoren closed 2 years ago

mgoren commented 6 years ago

Sometime in the last few days search queries such as the following have stopped returning any results for me:

client.list_leads(email: "example@example.com") 
# RESPONSE: {"has_more"=>false, "total_results"=>0, "data"=>[]}

Other queries are still working fine. For example this works: client.list_leads(name: "Example")

I also tested the API in python with the following and it worked fine: lead_results = client.get('lead', params={'query': 'email:"example@example.com"'})

Any idea if something changed with the Close API recently that would have caused this issue?

(I'm using gem v3.1.0.)

Thanks!

taylorbrooks commented 6 years ago

I assume that at one point, this call returned results as expected?

client.list_leads(email: "example@example.com") 
taylorbrooks commented 6 years ago

I just tested against my Close.io instance and it works as expected.

If you paste the email you're searching for into the Close.io app, do you get results? Maybe the email you're searching for was removed or the contact itself was removed.

mgoren commented 6 years ago

Weird! Thanks so much for looking into that for me.

Yes, that call did work fine in the past, and it still works fine searching for that email within the Close.io app and using the sample python code provided by Close. Is there maybe an alternate syntax I can use with your gem to test finding a lead by email? Maybe client.get(...)?

Thanks!

taylorbrooks commented 6 years ago

What's the result of this?

client.list_leads('example@example.com')
mgoren commented 6 years ago

That works. So I think I figured this out. In my testing outside of my app I was searching with code such as the following:

client.list_leads(email: "example@example.com")
# total_results == 0

But actually email: needs to be in quotes as well, as follows:

client.list_leads("email: example@example.com")
# total_results == 4 (though only one lead actually has that exact email)

This despite the fact that it seems to work either way for a name query:

client.list_leads(name: "Test")
client.list_leads("name: Test")
# These 2 queries return the same results.

An additional piece of why I had difficulty troubleshooting this is because even though my production app does the email query the way that works, all of the emails I was using for testing began returning more than one result (a recent change it seems), and my code expects total_results to equal 1 when doing an email query. For some reason Close (even in the app) often returns extraneous results even when searching for a specific email (results with similar emails for example), but I believe that in the past when querying via the API with an email query it actually did formerly return just the 1 result.

Thanks so much for your help and your work on this! If you know of a way to query Close to get it to only return the results with exact matching email, that would be great to know. I suppose I could just limit to 1 result and assume the first one is the one that matches most closely.

Thanks again for your help.

quantummachina commented 6 years ago

I am tracking the same issue, it stopped working for us yesterday or so. Our code also was running fine before, and I just tested that solution @mgoren came with. Thank you. Even it is a workaround, it will help. Still looking for what changed back there.

taylorbrooks commented 6 years ago

Something must've changed on the API side then.

Any changes in the service that would have an effect here?

cc @philfreo @nickpersico

nickpersico commented 6 years ago

@taylorbrooks @quantummachina @mgoren Thanks. I've pinged the team about this and we'll chime in soon.

jkemp101 commented 6 years ago

We are in the middle of migrating to some new infrastructure and it looks like it created this change in the search behavior. I will give another update shortly once we get to the bottom of this.

mgoren commented 6 years ago

Upon further experimentation, I figured out a fix.

Originally I had been searching as follows:

client.list_leads(email: "example@example.com")
# worked in the past but now returns 0 results

When that stopped working, I changed to the code I mentioned above:

client.list_leads("email: example@example.com")
# returns multiple results, including extraneous ones

This successfully returned results, but included extraneous ones. To retrieve only exact matches I included quotes around the entire query but also around the email within the query:

client.list_leads('email: "example@example.com"')
# returns just the exact match
jkemp101 commented 6 years ago

Following-up on this issue. We are in the middle of adding some more sophisticated email searching functionality by parsing addresses around the @ symbol. But this actually got inadvertently triggered in this particular case because the search terms are being single quoted instead of double quoted.

I believe all that needs to be done is change this line https://github.com/taylorbrooks/closeio/blob/94e52325ff2f1d8a76a0aee4586533a55efe3aab/lib/closeio/client.rb#L75 to query.map { |k,v| "#{k}:\"#{v}\"" }.join(' ') so it uses double quotes.

Should probably also check if it is already wrapped in quotes just to be safe.

taylorbrooks commented 2 years ago

I believe this issue has been fixed, but in the event that it hasn't, please open a new issue.