HubSpot OAuth integration example

I recently saw this job posting on Upwork that had a title of “HubSpot oAuth integration example.” The posting said:

I need you to make an OAuth integration example with HubSpot’s API:

http://developers.hubspot.com/docs/methods/auth/initiate-oauth

The steps for the flow should be:

  1. Click a link to go to HubSpot’s oauth page
  2. After login, user should be redirected to your script
  3. The oauth credentials should persist indefinitely until the user revokes them

After I read it I thought, “I can do that. And there are probably other HubSpot users that would find this useful as well.” So in this tutorial, I’m going to show you an example of an OAuth integration using the HubSpot API.

Instructions

Complete these other tutorials first

In order to create an OAuth integration in HubSpot, you’ll need a few other things. First, you’ll need to create a HubSpot Developer account. Then, you’ll need to create a HubSpot app. Finally, you’ll need to get the Client ID of the HubSpot app you created.

Download the file

Download the “hubspot-oauth-integration-example.php” file using the form below. Then, upload it to your web host.


The only part of the code that you need to edit is the Client ID at the top. I’ve included comments in the code so that you can understand how it works.