APIs & Integrations

Not applicable

"is-contact" returning "" when getting user via utk

Hi,

I have a custom form which makes a POST request to HubSpot’s form submission endpoint. The request is successful per a 204 status code returned.

Directly after the post request is made, the page makes a GET request to HubSpot’s contact retrieval endpoint via utk. The FIRST time that request is made, “is-contact” is empty. If I make the same request AGAIN then “is-contact” is 1.

I tried setting a sleep() in my script to see if HubSpot had some sort of delay, but this does not fix the problem.

Does anyone know why I would be getting “is-contact” as NULL for the first request, and then TRUE directly after it if I make an identical request?

0 Upvotes
10 Replies 10
Not applicable

"is-contact" returning "" when getting user via utk

@pmanca do you have any ideas on why this may be occurring?

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

"is-contact" returning "" when getting user via utk

@wd001 How are you making the call to the contact endpoint? Is it a client-side request?

0 Upvotes
Not applicable

"is-contact" returning "" when getting user via utk

It is a PHP cURL request.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

"is-contact" returning "" when getting user via utk

@wd001 How long was your sleep() for?

0 Upvotes
Not applicable

"is-contact" returning "" when getting user via utk

@pmanca It’s odd though, if I make the same request consecutively it always works properly the second time even if there’s not a significant time in between the two requests.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

"is-contact" returning "" when getting user via utk

@wd001 can you post how you are making you call? That doesn’t sound right to me.

0 Upvotes
Not applicable

"is-contact" returning "" when getting user via utk

@pmanca Here is my code making the request using the WP function wp_remote_get().

<?php

$hapikey = 'redacted';

$cookie = $_COOKIE['hubspotutk'];

$get = wp_remote_get(
    'http://api.hubapi.com/contacts/v1/contact/utk/' . $cookie . '/profile?hapikey=' . $hapikey,
    array(
        'sslverify' => false
    )
);
    
if (!$get->errors) {
    $body = json_decode($get['body']);

    # Code gets here, but not any further

    if ($body->{'is-contact'}) {

    # ...

    }
}

Similar deal with cURL, is-contact is false the first time:

<?php

$hapikey = 'redacted';

$cookie = $_COOKIE['hubspotutk'];

$endpoint = 'http://api.hubapi.com/contacts/v1/contact/utk/' . $cookie . '/profile?hapikey=' . $hapikey;

$ch = @curl_init();
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch);
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
@curl_close($ch);
    
$body = json_decode($response);
                
if ($body->{'is-contact'}) {
    # ...
}
0 Upvotes
Not applicable

"is-contact" returning "" when getting user via utk

This issue is now resolved, there was a problem with the synchronization. Thanks for the assistance.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

"is-contact" returning "" when getting user via utk

@wd001 I’m glad you got it figured out. Thanks for letting me know!

0 Upvotes
Not applicable

"is-contact" returning "" when getting user via utk

@pmanca I tried 5 and 30 seconds, neither one appeared to fix the problem.

0 Upvotes