APIs & Integrations

YFeng
Participant

Phone number is not returned when search for Contacts based on CreateDate

SOLVE

Hello experts,

My use case is to fetch Contacts created in the past certain period of time; for example, get all contacts created in the past 5 mins. So I use the Search API and Post to Contacts as below screenshot in Postman. But I realized the phone number of that contact is not returned (even though that contact has a phone number), along with other properties such as Lead Status are not returned. So my question is, how do I get all fields associated with those contacts based on my current API request? Thank you very much!

HubSpot Question.PNGHubSpot Question2.PNG

1 Accepted solution
himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Phone number is not returned when search for Contacts based on CreateDate

SOLVE

Hi @YFeng,

 

After the filter, you need to add all those properties in the request which you want to get in response like this -

 

 

{
  "filterGroups": [
    {
      "filters": [
        {
          "value": "testingapis@hubspot.com",
          "propertyName": "email",
          "operator": "EQ"
        }
      ]
    }
  ],
  "sorts": [
    "email"
  ],
  "properties": [
    "firstname",
    "phone"
  ],
  "limit": 1,
  "after": 0
}' 

 

 

I've had tested and here's the response that I received:

 

response.png

 

Hope this helps!!

 

Regards,

Digital Marketing & Inbound Expert In Growth Hacking Technology

View solution in original post

4 Replies 4
webdew
Guide | Diamond Partner
Guide | Diamond Partner

Phone number is not returned when search for Contacts based on CreateDate

SOLVE

Hi @YFeng,

In the search API only first name, phone, email and ID shown. If you want more info please contact detail API.




$live_webdew_hapikey = 'demo';
$args['url'] = 'https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey='.$live_webdew_hapikey;
$args['data'] = json_encode([
"filterGroups"=>[
[
"filters"=>[
[
"propertyName" => "email",
"operator" => "EQ",
"value" => 'test@gmail.com'
]
]
]
]
]);
$result = curlAccess('POST',$args);

if(!isset($result->status)){
if($result->total > 0){
$vid = $result->results[0]->id;

// update contacts
$args['url'] = 'https://api.hubapi.com/contacts/v1/contact/vid/'.$vid.'/profile?hapikey='.$live_webdew_hapikey;

$args['data']= json_encode([
"properties" => [
[
"property" => "email",
"value" => 'test@gmail.com'
]
]
]);

curlAccess('PUT',$args);
// update contact

} else {
// insert contacts

$args['url'] = 'https://api.hubapi.com/contacts/v1/contact/?hapikey='.$live_webdew_hapikey;

$args['data']= json_encode([
"properties" => [
[
"property" => "email",
"value" => 'test@gmail.com'
],
[
"property" => "firstname",
"value" => 'demo first'
],
[
"property" => "lastname",
"value" => 'demo last'
]
]
]);
$result = curlAccess('POST',$args);
// insert contact

if(!isset($result->status)){
$vid = $result->vid;
}
}
}


function curlAccess($method, $array, $content_type = 'array' ) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $array['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

switch ($method){
case "POST":
curl_setopt($ch, CURLOPT_POST, 1);
if ($array['data'])
curl_setopt($ch, CURLOPT_POSTFIELDS, $array['data']);
break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if ($array['data'])
curl_setopt($ch, CURLOPT_POSTFIELDS, $array['data']);
break;
default:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
}

$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);

if($content_type == 'array'){
$result = json_decode($result);
}

return $result;
}
Hope this helps!

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

Thanks and Regards.

0 Upvotes
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Phone number is not returned when search for Contacts based on CreateDate

SOLVE

My pleasure @YFeng,

 

So coming back to your question. Yes, you can pass the properties that you want in return on search ( not sure if you can get all properties ).

 

For more information, please check the endpoint tab here and select Filter, Sort, and Search CRM Objects endpoint - https://developers.hubspot.com/docs/api/crm/contacts

 

I hope this will help (If yes, please make sure to mark it as a solution 😁).

 

Regards,

Digital Marketing & Inbound Expert In Growth Hacking Technology
0 Upvotes
YFeng
Participant

Phone number is not returned when search for Contacts based on CreateDate

SOLVE

Hello Himanshu,

 

Thank you for your quick response! Is there any way I can merge these requests into 1? Meaning if there is a way to get the phone number and other fields while searching for Contacts created in the past 5 mins? The reason I am asking is that the number of contacts returned on my first request is dynamic; it could return 2 contacts or 200 contacts, so it would be difficult to make a second call and pass all of their emails as parameters. My use case is to fetch all contacts created in the past 5 mins and return all their associated fields, is there a better way to do it? Thanks a lot!

Thanks,

Yvonne Feng

 

 

himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Phone number is not returned when search for Contacts based on CreateDate

SOLVE

Hi @YFeng,

 

After the filter, you need to add all those properties in the request which you want to get in response like this -

 

 

{
  "filterGroups": [
    {
      "filters": [
        {
          "value": "testingapis@hubspot.com",
          "propertyName": "email",
          "operator": "EQ"
        }
      ]
    }
  ],
  "sorts": [
    "email"
  ],
  "properties": [
    "firstname",
    "phone"
  ],
  "limit": 1,
  "after": 0
}' 

 

 

I've had tested and here's the response that I received:

 

response.png

 

Hope this helps!!

 

Regards,

Digital Marketing & Inbound Expert In Growth Hacking Technology