Integration through Apex

Highlighted
New Contributor

Hi,

 

I am trying to make an integration between Salesforce and HubSpot via APIs.

I'm not understanding how to get HubSpot Access Token through APEX.

 

When I make API Call to this endpoint : https://app.hubspot.com/oauth/authorize?grant_type=authorization_code. I am getting 200 status code but response body is returned with some html code.

 

I'm trying to achieve this integration using batch class in apex.

 

 

 

Reply
0 Upvotes
1 Reply 1
Community Manager

Hey @sracharla_v ,

 

I'm not particularly familiar with Apex, but I can give some info on the HubSpot OAuth flow. Here is the overview page; the steps required to make an OAuth connection are as follows:

  • Build the authentication URL for your app, and send the HubSpot user to that URL. 
  • After the user grants access, they'll be returned to your app, with a code appended to the URL.
  • Use that code and your Client Secret to get an access_token and refresh_token.

Once you've completed this process, you can use the access_token to authenticate requests to the HubSpot API, and the refresh_token to generate new access_tokens when the previous one expirse.

 

The URL you included is a partially complete authorization URL, which is part of the first step mentioned above. You (or, a user in the account you're generating tokens for) needs to navigate to the fully constructed version of that URL and approve the installation. Then you can proceed with the following steps.

 

If you'd like to check out an example of what this looks like in code, you should check out the OAuth Quickstart Guide. This is an example app created by our product team that illustrates how exacty the OAuth flow works.

Reply
0 Upvotes