APIs & Integrations

MShekar
Participant

Need to have lookup between custom object's field and contacts email field

SOLVE

Hi Team,
I need to create a lookup for my custom object's field to the contacts the email field.
As I need to have a form for custom object data entered by the user, so I have an email field in a custom object, where once the new record is created in a custom object, the contacts with the same email should have a lookup to custom object's record.


Thank you 

1 Accepted solution
webdew
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Need to have lookup between custom object's field and contacts email field

SOLVE

Hi @MShekar ,

Please tried below code. Search email from custom object row from existing email :

<?php
$url = "https://api.hubapi.com/crm/v3/objects/<objectID>/search?hapikey=demo";
$data = '{
"filterGroups":[
{
"filters":[
{
"propertyName": "email",
"operator": "EQ",
"value": "test@gmail.com"
}
]
}
]
}';


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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);
$result = json_decode($result);

if(isset($result->total)){
if($result->total > 0) {
$record_id = $result->results[0]->id;
return 'true';
} else {
return 'false';
}
}

Hope this helps!

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

Thanks and Regards. 

View solution in original post

2 Replies 2
webdew
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Need to have lookup between custom object's field and contacts email field

SOLVE

Hi @MShekar ,

Please tried below code. Search email from custom object row from existing email :

<?php
$url = "https://api.hubapi.com/crm/v3/objects/<objectID>/search?hapikey=demo";
$data = '{
"filterGroups":[
{
"filters":[
{
"propertyName": "email",
"operator": "EQ",
"value": "test@gmail.com"
}
]
}
]
}';


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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);
$result = json_decode($result);

if(isset($result->total)){
if($result->total > 0) {
$record_id = $result->results[0]->id;
return 'true';
} else {
return 'false';
}
}

Hope this helps!

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

Thanks and Regards. 

dennisedson
Community Manager
Community Manager

Need to have lookup between custom object's field and contacts email field

SOLVE

@lynton , any advice here?

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
0 Upvotes