Searching contacts having last name as empty string

I’m trying to use the endpoint ‘search’ to find contacts having first_name as empty string. Like we can do in the frontend using the filter where First Name “is unknown”. But I getting the following error:
Cannot construct instance of `com.hubspot.inbounddb.publicobject.core.v3.search.Filter`, problem: value must be non-empty and non-blank, if specified’

example of request (I’m omiting here the sorts, etc)

curl --request POST \
--url ‘https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=YOUR_HUBSPOT_API_KEY’ \
--header ‘content-type: application/json’ \
--data '{
“filterGroups”: [
{
“filters”: [
{
“value”: “”,
“propertyName”: “firstname”,
“operator”: “EQ”
}


}

Is there any way to get this info throught the API ?

@ascavalcante

Instead of query for the equality, you should query to see if the property has a value. Then you can exclude the “value” altogether.

Example:

{
 "filters": [
 {
 "propertyName": "firstname",
 "operator": "NOT_HAS_PROPERTY"
 }
 ]
}

Note that I did not use a filter group as I am only querying for one thing

It worked just fine! Thanks a lot!

Hi @ascavalcante ,
Below php code will help for you
<?php
$data = ‘{
“filterGroups”:[
{
“filters”: [
{
“propertyName”: “firstname”,
“operator”: “NOT_HAS_PROPERTY”
}
]
}
]
}’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=YOUR_HUBSPOT_API_KEY’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$headers = array();
$headers[] = ‘Content-Type: application/json’;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo ‘Error:’ . curl_error($ch);
}
curl_close($ch);
?>

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.

Thanks a lot @webdew ! I used the solution provide by dennisedson