APIs & Integrations

PCarlson
Participant

Link to Authenticated HubSpot page

SOLVE

I want to be able to authenticate using OAuth, then create a link from an external app back to a HubSpot page under the user login account selected during authentication. For example to let the user transition to working directly in the HubSpot UI.

 

What's the best way to get the base url so I can create links to contacts, deals, etc.?

 

Get Information for OAuth 2.0 Access Token says you can get metadata for a token and includes the hub_id. Is that the string to put in a url like https://app.hubspot.com/contacts/1234567/contacts/list/view/all/ or similar (i.e. in place of 1234567)?

 

I'm still new to the HubSpot API and I don't know all the terminology yet, so feel free to point me to docs with basic definitions like what a hub_id is. I'm specifically using the Nodejs api library.

0 Upvotes
1 Accepted solution
PCarlson
Solution
Participant

Link to Authenticated HubSpot page

SOLVE

I was able to dig through the Nodejs library code and find the getAccessToken() call. That returns among other data the hubId and userId in the AccessTokenInfoResponse object as in this crude code example:

 

  console.log('=== Retrieving AccessTokenInfoResponse object for my token ===')
  const result = await hubspotClient.oauth.defaultApi.getAccessToken(accessToken)
  console.log('');
  console.log(result.body)

 

That code displays a hubId consistent with the id in URL when I view pages in HubSpot for the linked account, confirming my guess above. So I can use the hubId to create links back to HubSpot contact and other pages.

 

Also note that this posted solution says the only way to get the user id "is through this endpoint: Get Information for OAuth 2.0 Access Token. " That was back in May 2020, so this library call may be new, but I was able to get the user id through the library call rather than https endpoint.

 

Also note it provides user, hubDomain, scopes, expiresIn, etc.

 

Phil

View solution in original post

2 Replies 2
PCarlson
Solution
Participant

Link to Authenticated HubSpot page

SOLVE

I was able to dig through the Nodejs library code and find the getAccessToken() call. That returns among other data the hubId and userId in the AccessTokenInfoResponse object as in this crude code example:

 

  console.log('=== Retrieving AccessTokenInfoResponse object for my token ===')
  const result = await hubspotClient.oauth.defaultApi.getAccessToken(accessToken)
  console.log('');
  console.log(result.body)

 

That code displays a hubId consistent with the id in URL when I view pages in HubSpot for the linked account, confirming my guess above. So I can use the hubId to create links back to HubSpot contact and other pages.

 

Also note that this posted solution says the only way to get the user id "is through this endpoint: Get Information for OAuth 2.0 Access Token. " That was back in May 2020, so this library call may be new, but I was able to get the user id through the library call rather than https endpoint.

 

Also note it provides user, hubDomain, scopes, expiresIn, etc.

 

Phil

dennisedson
HubSpot Product Team
HubSpot Product Team

Link to Authenticated HubSpot page

SOLVE

@PCarlson 

Thanks for updating this post with your solution! 

0 Upvotes