Getting Started - Initial


#1

I am trying to make an initial call to get contact by email, these are first tests. It is not returning anything, does anyone have any ideas - does the IP of the server need to be whitelisted? I didn't see that anywhere.

https://api.hubapi.com/contacts/v1/contact/email/ahomco@emich.com/profile?hapikey={api key here}

$hapi_key = '{api key here}';
$email = 'ahomco@emich.com';
$url = 'https://api.hubapi.com/contacts/v1/contact/email/'.$email.'/profile?hapikey='.$hapi_key;
echo '

'.$url.'

';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
var_dump($data);
exit;

#2

Have you tried just putting the URL into a browser and see what comes back?


#3

Thanks for that suggestion, it comes back with the JSON including "contact does not exist". As a result I can look more closely at why the way I was calling it didn't work / get a response...


#4

Another useful program is Postman which will let you do posts easily as well and can have tabs for different calls. Very useful when learning APIs like this.


#5

Whats weird at this point is that I got the JSON response via browser, but I have tried cURL and PHP's file_get_contents, and it returns NULL:

$hapi_key = '{api key here}';
$email = 'ahomco@emich.com';
$url = 'https://api.hubapi.com/contacts/v1/contact/email/'.$email.'/profile?hapikey='.$hapi_key;
$result = file_get_contents($url);
var_dump($result);
exit;


#6

Curl command line works for me:
curl https://api.hubapi.com/contacts/v1/contact/email/foo@example.com/profile?hapikey=demo

I don't have PHP installed - But I tried phpfiddle.org and that worked too.

<?php

$hapi_key = 'demo';
$email = 'foo@example.com';
$url = 'https://api.hubapi.com/contacts/v1/contact/email/'.$email.'/profile?hapikey='.$hapi_key;
echo '

'.$url.'

';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
var_dump($data);
exit;

?>

outputs

https://api.hubapi.com/contacts/v1/contact/email/foo@example.com/profile?hapikey=demo string(155) "{"status":"error","message":"contact does not exist","correlationId":"4d192aed-9202-476a-83a0-fcd587b17ce1","requestId":"5702fadf179a5d5563fe64760716103a"}"

Curl won't send any headers by default I think - maybe you're behind a firewall that blocks headerless requests?
I tried your file_get_contents one too - but that just returned a 404 not found error


#7

So I did the exact same thing to help break this down:

<?php $hapi_key = 'demo'; $email = 'foo@example.com'; $url = 'https://api.hubapi.com/contacts/v1/contact/email/'.$email.'/profile?hapikey='.$hapi_key; echo '

'.$url.'

'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); var_dump($data); exit; ?>

And I get:

https://api.hubapi.com/contacts/v1/contact/email/foo@example.com/profile?hapikey=demo

bool(false)

I double checked that the cURL extension is installed for PHP, which it is installed...


#8

I've never used cURL from PHP (and not used PHP for many many years either). However googling curl_exec returns false brought up this link:

Try doing what that suggests to get the error message out and we can go from there.


#9

Thanks, that was very close. I found I needed this for now, and to address some server level SSL items later:

curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);

Found the solution here:

Thanks Nigel!


#10

Yay! Glad I could help.