APIs & Integrations

jhuddles
Participant

Only run identify API / set new properties if a person is not already a contact

Hello!

 

We send people to a page with a URL parameter that includes ?email=example@something.com, and this code below does a great job of doing what it's supposed to do – Creating a new contact from the email and giving them this property of "autocreated_pricing_page" as Yes. 

 

However... this also just updates this "autocreated_pricing_page" parameter for someone even if they already were a contact. I'm trying to only have this property be associated with NEW contacts created from this page, not just anyone who happens to visit with the ?email= parameter in the URL.

 

Would there be a way to run this conditionally based on something like is-contact: false? I am fairly a newbie at this, so please excuse me if this is a crazy thing to ask. Thanks!!

 

_hsq.push(['trackPageView']);

function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

var _hsq = window._hsq = window._hsq || [];
_hsq.push(["identify",{
    email: getParameterByName("email"),
    autocreated_pricing_page: true
}]);

 

0 Upvotes
3 Replies 3
Mike_Eastwood
Key Advisor | Gold Partner
Key Advisor | Gold Partner

Only run identify API / set new properties if a person is not already a contact

Hi @jhuddles 

 

You could use the API method "Get a contact by email address" to check to see if the Contact exists in HubSpot.

  • If the email exists the request returns a 200 response with contact information in the body.
  • If the email does not exist it returns a 404 response.

Have fun

Mike

jhuddles
Participant

Only run identify API / set new properties if a person is not already a contact

Thanks @Mike_Eastwood !

 

I appreciate the response and a clue to what I could look into next but... is it okay to ask ~how~ I could use which response it returns to decide if the Identify should run?

 

I'm running at the extent of my dev knowledge here. Smiley Embarassed

0 Upvotes
Mike_Eastwood
Key Advisor | Gold Partner
Key Advisor | Gold Partner

Only run identify API / set new properties if a person is not already a contact

Hi @jhuddles 

 

There's lots to learn when working with the HubSpot APIs.

 

I would start here: https://developers.hubspot.com/docs/overview

 

And check out HubSpot Academy for this short course.

 

Look for an SDK in the language of your choice. We've been using this SDK for PHP.

 

Personally I'm more experienced with PHP so I do the heavy lifting before the page loads. If I need anything asynchronous then I use AJAX to call my PHP.

 

Have fun

Mike

 

 

0 Upvotes