Our cursor poller for contacts recently started failing, and the resulting message only tells us there was some issue, but doesn´t specify why.
Here is the code that breaks:
client = hubspot.Client.create(access_token=HUBSPOT_API_KEY)
with open ('columns', 'rb') as fp:
columns = pickle.load(fp)
if ascending:
public_object_search_request = PublicObjectSearchRequest(
filter_groups=[
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "GT",
"value": cursor.datetime,
}
]
}
],
sorts=[{"propertyName": "lastmodifieddate", "direction": "ASCENDING"}],
properties=columns,
limit=200 )
else:
public_object_search_request = PublicObjectSearchRequest(
filter_groups=[
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "LT",
"value": cursor.datetime,
}
]
}
],
sorts=[{"propertyName": "lastmodifieddate", "direction": "DESCENDING"}],
properties=columns,
limit=200)
api_response = client.crm.contacts.search_api.do_search(public_object_search_request=public_object_search_request)
The search response is a status 400 with the following body
{"status":"error","message":"There was a problem with the request.","correlationId":"e3997f3e-c69d-436d-b351-25eabd0b9235"}
Hey, @SebTorres
Thanks for including your details. Have you tried running a couple of simplified tests using Postman? Just to verify that the search endpoint works as expected outside your custom code? — Jaycee
Something simple like this:
Test 1
Body:
{
"properties": ["email", "firstname", "lastname", "lastmodifieddate"],
"limit": 10
}
Test 2 (adding filter group)
{
"filterGroups": [
{
"filters": [
{
"propertyName": "lastmodifieddate",
"operator": "GT",
"value": "1640995200000"
}
]
}
],
"properties": ["email", "firstname", "lastmodifieddate"],
"sorts": [{"propertyName": "lastmodifieddate", "direction": "ASCENDING"}],
"limit": 10
}
Talk soon! — Jaycee
Hi, Jaycee! I did try running a curl request independently, but using the same body formed by the PublicObjectSearchRequest. It went through, no problem
Thanks for the update. Hey @evaldas @MichaelMa do you have any other troubleshooting tips you can share? Thank you! — Jaycee
You mentioned that you tested using the same body formed but is it the same body being sent to Hubspot? Since these requests are erroring out, you can pull the body from the API logs and verify if the data being sent is correct and matches what you’re testing with?
That is basically what I did. I sent the body to print, and copied all that into my curl request. That is what is most confusing of all
That is strange. Would you mind posting the payload for us to test ourselves?
The code looks fine and the only issue I could see is with the variables cursor.datetime and columns (whose data is outside the code you posted).
I guess a followup question, is it still happening? Could it have been just a hiccup with their API?
Found the issue! As you said, the value of cursor had a whitespace that the terminal was skipping, so the request worked there. Marking as solved. Thank you!
Amazing! Thank you very much for coming back and sharing the root cause
— Jaycee