APIs & Integrations

MRaemen
Member

How does the Contacts API work by usertoken?

Hi all,

 

I am trying out the Contacts API (https://legacydocs.hubspot.com/docs/methods/contacts/get_batch_by_user_token_with_token_keys) and passing my API key and my own usertoken and it is returning a blank object.

 

My API key seems correct (as it returns an error when I slightly change it) and the usertoken is the one I get from the __hsUserToken variable I get in the console of my web application (I am known in the Hubspot database and have filled out some forms etc already).
The demo (https://api.hubapi.com/contacts/v1/contact/utks/batch/?hapikey=demo&utk=6084e7de6a2b6f11f31d976090c4...) does return a record, so I am clueless. Does anyone have any I idea what I might be doing wrong or if there are any limitations to the API that I am missing?

Thanks

0 Upvotes
3 Replies 3
dennisedson
HubSpot Product Team
HubSpot Product Team

How does the Contacts API work by usertoken?

@MRaemen 

Are you sure you are using the correct token?  Should be in the hubspotutk cookie.

@zaklein , any other thoughts?

 

0 Upvotes
MRaemen
Member

How does the Contacts API work by usertoken?

Hi @dennisedson it must be, I get the exact same result for "__hsUserToken" from my browser console as I get for "getCookie('hubspotutk')" => 54a354fecdc2303fe27d3baae428984a

0 Upvotes
zaklein
Contributor | Diamond Partner
Contributor | Diamond Partner

How does the Contacts API work by usertoken?

Hi @MRaemen 

I haven't been able to recreate the issue you're experiencing. I tested by grabbing the browser cookie value contained in hubspotutk and submitted that as the value for the query string parameter utk. My contact record was returned successfully. Here's my call:

 

GET https://api.hubapi.com/contacts/v1/contact/utks/batch?utk=8fa453fd31992755defd80909e16a813&hapikey={{MY_KEY}}

 

I'd recommend double-checking:

  1. The hapikey you're using belongs to the portal where you'd expect the relevant Contact record to exist.
  2. That you're getting all instances of the hubspotutk cookie on your browser. In my testing, I found multiple instances of the cookie hubspotutk -- 1 returned a blank object from the HubSpot API endpoint above, the other successfully returned my HubSpot Contact record.

If that doesn't help, can you please send through your API call details (with your API key redacted)?

All the best,

Zach