I’m querying Hubspot for a particular Contact using the email. The code I’m using is very standard:
body = {
“filterGroups”: [ {
“filters”:[ {
‘value’: ‘example@example.com’,
‘propertyName’: ‘email’,
‘operator’: ‘EQ’
}]
}]
}
api_response = api_client.crm.contacts.search_api.do_search(body: body)
The problem I’m experiencing is that when calling this code for a particular email I get the record with the Contact from Hubspot but if I make the exact same call again a few seconds later sometimes, very randomly, I get 0 results:
{:total=>0, :results=>[]}
Since I don’t get any error I cannot differentiate when there is no data from when no data is returned making this service totally unusable for our company.
Any idea how this could be happening? and how could I get around it?
Hey, @ECartagena
Welcome to our community! Thank you for your question and for including your example.
I don’t have the answer, and I do have a few questions to help our community better understand your issue:
- If it’s a timing issue, would you mind trying adding a delay (if you haven’t already) between creating/updating a contact and searching for it?
- Could you also check if there are any rate limiting or networking issues that might be causing the inconsistency? It’s helpful to have error logs or more details about the request and response headers, if possible.
- When you experience this issue, does it occur with all contacts, or just specific ones? Moreover, how long does this behaviour last for a specific contact?
- Is this happening for a Contact or Contacts that are newly created and then searched for? Or are these contacts pre-existing?
Thank you for the additional details! — Jaycee
Hi Jaycee,
thank you for trying to solve the problem I’m experiencing. Answering your questions:
- At first I thought it was a timing issue and for that I added a huge 10 seconds delay to my tests but to my surprise it did not solve the problem. It probably reduced the frequency but the problem was still occurring.
- I’m not aware of any rate limiting or networking issues that might be causing the inconsistency. We also access other apis like Stripe and this one is the only one causing a problem.
- The tests I’m running are related to creating a Contact, retrieving it to make sure it’s created, modifying it, retrieving it to make sure its updated correctly, modifying it again and retrieving it again to make sure the second update went well as well.
As a first attempt to solve the problem I repeated the search for the hubspot contact inside a loop until I got a record back with a 2 seconds delay in between. The tests usually required 4 or 5 calls until it got a result back. This way I managed to get all my tests passing but obviously this is not a valid solution for production code because in case there is genuinely no contact with a particular email the code will go through all the calls taking about 20 seconds just to get no results.
Another test I have done, and this one completely blew my mind and made me think Hubspot api for search is unusable, is the following:
1- I create a contact
2- I search for the contact and I get the contact correctly
3- I try to update the contact and the first thing I do is check if the Contact exists already by searching by email. This time the search returns no record. How could this be if just before I got a record back.
Since this was so puzzling I debugged this test and when I got no results on step 3 I run the search query again and this time I got the record back.
I had to run this test several times because the problem happens only from time to time. Maybe 1 out of 10 times.
Thanks again for your help.
I really hope we can get to the root of this problem.
Hi. We are experiencing the same kind of issue with the searchApi methods. Did you find a way / workaround to solve efficiently this problem?
@lemlistDev we did not find a workaround. That problem renders the Hubspot API unusable for us. Fortunately this currently affects us on some automated tests which we had to add huge delays to make sure data is returned correctly.
I have the impression that the searchAPI targets a different database that take quite a bit of time to get synchronized from the main database.