Retrieving contact details via GTM


#1

Hi there,

I’d love to retrieve some specific contact properties via use of Google Tag Manager so that I can store it in a variable field there.

In order to do this I figured I’d probably need to read the hubspotutk cookie so that I can then get a contact record by its vid. Then, I would need to fill a variable with the property I’m looking for, and then the rest of the GTM magic can happen.

Currently I’m a bit stuck on the first bit already. I’ve figured out a way to read the hubspotutk cookie but which API call should I then do? I’ve tried using this url:

http://api.hubapi.com/contacts/v1/contact/utk/xxx/profile?hapikey=yyy

with xxx being the content from the cookie, and the hapikey being my hapikey that I’ve gotten upon making a dev account. It seems as though the dev account is a completely different account than the one I’m trying to get data from. Would that API key still actually work then? Because for me it currently seems like that’s not the case.

Also, I think after I’ve retrieved the json in a variable (lets call it json) and I’d like to retrieve lets say the last name (as an example), I think i’d be using the command json.contacts.lastname.value, right?

I hope you guys can help me out!


#2

Actually, even the example URL on the get a contact record by its vid page gives me the exact same error.

https://api.hubapi.com/contacts/v1/contact/vid/324574/profile?hapikey=demo

results in the following error for me:

{“status”:“error”,“message”:“contact does not exist”,“correlationId”:“08f43fcc-9fcc-4534-9656-ae7ab12cff04”,“requestId”:“65430a94a699dcd1f2ae6c85ad05f2c0”}


#3

@Hugom You need to use the Hapikey from the portal you are trying to get the contact from and not the Hapikey from your developers portal. You can get you Hapikey under integrations in your normal portal.


#4

Thanks @pmanca ! That helped me get one step further.

I seem to have a different result now. I seem to have got the correct API call, but the result is empty when I view it. I could PM it to you perhaps?


#5

@Hugom Can you confirm the contact vid is real? Can you see the contact in the UI?