{"id":677,"date":"2019-11-28T10:41:44","date_gmt":"2019-11-28T10:41:44","guid":{"rendered":"https:\/\/www.dhruvsoft.com\/blog\/?p=677"},"modified":"2024-07-26T09:41:20","modified_gmt":"2024-07-26T09:41:20","slug":"hubspot-integration-guide-using-hubspot-api-to-integrate","status":"publish","type":"post","link":"https:\/\/www.dhruvsoft.com\/blog\/hubspot-integration-guide-using-hubspot-api-to-integrate\/","title":{"rendered":"Hubspot Integration Guide &#8211; Using Hubspot API to Integrate"},"content":{"rendered":"\n<p><strong>What is Hubspot?<\/strong><\/p>\n\n\n\n<p>HubSpot is an all-in-one business automation tool that helps an Organization to attract clients, convert them into a lead and close the deal effectively bringing the best results for a business. It has been described as unique because it strives to provide its customers with an all-in-one approach.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Hubspot-Integration-Guide-Using-Hubspot-API-to-Integrate.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"480\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Hubspot-Integration-Guide-Using-Hubspot-API-to-Integrate.jpg\" alt=\"Hubspot Integration Guide  Using Hubspot API to Integrate\" class=\"wp-image-687\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Hubspot-Integration-Guide-Using-Hubspot-API-to-Integrate.jpg 840w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Hubspot-Integration-Guide-Using-Hubspot-API-to-Integrate-300x171.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Hubspot-Integration-Guide-Using-Hubspot-API-to-Integrate-768x439.jpg 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/a><\/figure><\/div>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Features of Hubspot<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Blogging<\/li><li>Calls-to-Action and Landing Pages<\/li><li>Email Marketing<\/li><li>Marketing Automation<\/li><li>Lead Management<\/li><li>Analytics<\/li><li>CMS<\/li><li>Social Media<\/li><li>SEO<\/li><li>Salesforce Integration<\/li><li>Ads<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Hubspot Integration<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">Hubspot Authentication using OAuth 2.0<\/h4>\n\n\n\n<p>There are two means of authentication provided by Hubspot API, OAuth, and API key. It is an easy and fast process to authenticate using API key, but for a secured and commercial use Hubspot highly recommends OAuth.<\/p>\n\n\n\n<p>Almost all the endpoints support both OAuth and API keys, there are very few endpoints which only support OAuth ( like timeline events ). Irrespective of the authentication used, the requests are identical and would return the same results.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create a Developer Account<\/h4>\n\n\n\n<p>The best way to get started is by creating developer accounts. From this developer account, you can spin up test accounts that have their own API keys. To get started with OAuth you need to create an application using a developer account, you can create a developer account <a href=\"https:\/\/developers.hubspot.com\/cs\/c\/?cta_guid=20e606fd-fc0f-405c-8699-5d8611d5a6a3&amp;placement_guid=b4857ff3-6ca3-4fa8-b23c-6f79b958d7cb&amp;portal_id=428357&amp;canon=https%3A%2F%2Fdevelopers.hubspot.com%2Fdocs%2Fmethods%2Fauth%2Foauth-overview&amp;redirect_url=APefjpHt0UaPt-HQINvjAB3InlfBmVa76vm6foZiWdn17PJaqiBtTMEGOs13XmBg14xg_uMfHKRkrCbgTxnvjL0JIxJi8dlw4a1ZuVnaH_BuUULAzLzmMLYWZnLVDTySZHRnxrLbgZuEllKkYhyl0eJzJm1y6YbqUSdbov8COp-sPWOrTcXMDT0HqhgOSrOsq2wc4cSlxnh8TuS1rgGiEV-Vok6xeN1A4q5cwol57X8ZNC9YiCByvPYy-oibZXKKH2cLoT6qkzYfObd0ny8EJEnzFAPgsSGd1A&amp;click=390a9f53-2664-4145-9e5f-9948d463889c&amp;hsutk=3746ac34af23ebb62ff00aa34ae05812&amp;signature=AAH58kGe-AD8XoWp4Pp7I6us3KQA_tJgww&amp;utm_referrer=https%3A%2F%2Fwww.google.com%2F&amp;pageId=2166585153&amp;__hstc=20629287.3746ac34af23ebb62ff00aa34ae05812.1572401647647.1572401647647.1572401647647.1&amp;__hssc=20629287.5.1572401647648&amp;__hsfp=2490022465&amp;contentType=standard-page\">here<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-a-Developer-Account.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"523\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-a-Developer-Account-1024x523.jpg\" alt=\"Create a Developer Account\" class=\"wp-image-678\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-a-Developer-Account-1024x523.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-a-Developer-Account-300x153.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-a-Developer-Account-768x392.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-a-Developer-Account.jpg 1093w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Create an App in Hubspot<\/h4>\n\n\n\n<p>You need to create an app in order to initiate the OAuth connection. When you authenticate your integration using OAuth, the details for your app are shown to the user at the time of authorizing the connection. Before creating an App in Hubspot please make sure that you already have a developer account. To create an App, click on the <strong>&#8220;Apps&#8221;<\/strong> tab on the navigation and you should get a screen like below. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-an-App-in-Hubspot.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"461\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-an-App-in-Hubspot-1024x461.jpg\" alt=\"Create an App in Hubspot\" class=\"wp-image-679\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-an-App-in-Hubspot-1024x461.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-an-App-in-Hubspot-300x135.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-an-App-in-Hubspot-768x346.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Create-an-App-in-Hubspot.jpg 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>While creating an app, you&#8217;ll get a screen showing the settings for your new app. The name of your app will be displayed to the users when they authenticate your app with HubSpot. You will additionally see the other settings for your app, as well as the description, and choices for adding support contact information. You&#8217;ll also have the ability to upload the logo and a wordmark that will be displayed to HubSpot users. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/settings-for-your-app.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"465\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/settings-for-your-app-1024x465.jpg\" alt=\"settings for your app\" class=\"wp-image-681\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/settings-for-your-app-1024x465.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/settings-for-your-app-300x136.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/settings-for-your-app-768x349.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/settings-for-your-app.jpg 1082w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>You will also find the Auth settings for your app, including the<strong> client ID, client secret and scopes<\/strong> used by your app. These items are mandatory for Authorization. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/client-secret-and-scopes.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"467\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/client-secret-and-scopes-1024x467.jpg\" alt=\"client secret and scopes\" class=\"wp-image-680\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/client-secret-and-scopes-1024x467.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/client-secret-and-scopes-300x137.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/client-secret-and-scopes-768x350.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/client-secret-and-scopes.jpg 1055w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Initiating the Integration<\/h4>\n\n\n\n<p>In this article, I&#8217;m using Flask ( A Python framework ) for the authentication with Hubspot. I have created a small flask application for this authentication, click here for the <strong><a href=\"https:\/\/pastebin.com\/cPefN6bs\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Code (opens in a new tab)\">Code<\/a><\/strong>. If you are new to Flask then follow the instructions from this <a href=\"https:\/\/www.tutorialspoint.com\/flask\/flask_application.htm\">tutorial<\/a>. Once you save the code and run the file, please follow the steps below:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">step 1:&nbsp;<\/h4>\n\n\n\n<p>In this step, you will get the <strong>&#8220;Authorization code&#8221;<\/strong>. The URL for this function is \u00e2\u20ac\u02dc<a href=\"http:\/\/127.0.0.1:5000\/get-auth-code'\">http:\/\/127.0.0.1:5000\/get-auth-code<\/a>\u00e2\u20ac&#x2122;. Before executing the file you need to update values of the following variables (<strong>CLIENT_ID <\/strong>and <strong>CLIENT_SECRET<\/strong>). Once you hit the above URL it will redirect you to a page where you need to select an application as shown in the picture below. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/choose-an-account.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"457\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/choose-an-account-1024x457.jpg\" alt=\"choose an account\" class=\"wp-image-682\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/choose-an-account-1024x457.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/choose-an-account-300x134.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/choose-an-account-768x343.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/choose-an-account.jpg 1084w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>After selecting the application, you will be asked to grant access for Integration. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"545\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/request-for-integration-permissions.jpg\" alt=\"request for integration permissions\" class=\"wp-image-683\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/request-for-integration-permissions.jpg 849w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/request-for-integration-permissions-300x193.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/request-for-integration-permissions-768x493.jpg 768w\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" \/><\/figure><\/div>\n\n\n\n<p>As soon as you click on the &#8220;<strong>Grant access<\/strong>&#8221; button, you will be redirected to a URL having the auth_code as a parameter. The URL looks like this as shown below. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"42\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/grant-access-1024x42.jpg\" alt=\"grant access\" class=\"wp-image-684\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/grant-access-1024x42.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/grant-access-300x12.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/grant-access-768x31.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/grant-access-1140x47.jpg 1140w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/grant-access.jpg 1148w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>Please copy the code somewhere, as it is mandatory for the further steps.<\/p>\n\n\n\n<p><strong>step 2:<\/strong><br>In this step, you will get the &#8220;<strong>access token<\/strong>&#8220;. The URL for this function is <a href=\"http:\/\/127.0.0.1:5000\/get-access-token'\">&#8216;http:\/\/127.0.0.1:5000\/get-access-token&#8217;<\/a>. Before executing the file you need to update the value of the variable named \u00e2\u20ac\u02dc<strong>CODE\u00e2\u20ac&#x2122;<\/strong>. Once you hit the above URL it will return a JSON data with <strong>access_token, expires_in and refresh_token<\/strong>. Please copy the access_token and refresh_token somewhere. Remember, the access token will gets expired in 6 hours. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"91\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/access-token-1024x91.jpg\" alt=\"access token\" class=\"wp-image-685\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/access-token-1024x91.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/access-token-300x27.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/access-token-768x68.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/access-token.jpg 1067w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">step 3:<\/h4>\n\n\n\n<p>As the access token will no longer valid after 6 hours, you need to get a new access token every 6 hours. In this step, you will refresh the &#8220;access token&#8221; using &#8220;refresh token&#8221;. The URL for this function is <a href=\"http:\/\/127.0.0.1:5000\/get-refresh-token'\">&#8216;http:\/\/127.0.0.1:5000\/get-refresh-token&#8217;<\/a>. Before executing the file you need to update the value of the variable named<strong> &#8216;REFRESH_TOKEN&#8217;<\/strong>. Once you hit the above URL it will return a JSON data with access_token, expires_in and refresh_token.<\/p>\n\n\n\n<p>After getting the access token, you can start retrieving and manipulating data of different objects in Hubspot like contact, company, Deal and many more. That is all about the introduction of Hubspot and initiating integration with Hubspot using OAuth 2.0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, redirect\nimport requests\nimport json\n\napp = Flask(__name__) \n\nCLIENT_ID = 'ENTER CLIENT ID HERE'\nCLIENT_SECRET = 'ENTER CLIENT SECRET HERE'\nCODE = 'ENTER CODE HERE'\nREFRESH_TOKEN = 'ENTER REFRESH_TOKEN HERE'\n\n\n@app.route('\/get-auth-code') \ndef get_oauth_code():\n    CLIENT_ID = 'ENTER CLIENT ID HERE' # update the client Id  \n    url = f'https:\/\/app.hubspot.com\/oauth\/authorize?client_id={CLIENT_ID}&amp;scope=contacts&amp;redirect_uri=https:\/\/127.0.0.1:5000'\n    return redirect(url, code=302)\n\n@app.route('\/get-access-token') \ndef get_access_token():\n\n    data = {\n        'grant_type' : 'authorization_code',\n        'client_id' : CLIENT_ID,\n        'client_secret' : CLIENT_SECRET,\n        'scope' : 'contacts',\n        'redirect_uri' : 'https:\/\/127.0.0.1:5000',\n        'code' : CODE\n    } \n\n    headers = {'Content-Type' : 'application\/x-www-form-urlencoded;charset=utf-8'}\n\n    url = 'https:\/\/api.hubapi.com\/oauth\/v1\/token'\n    resp = requests.post(url, data = data, headers = headers)\n    return resp.json()\n\n@app.route('\/refresh-access-token') \ndef refresh_access_token():\n    data = {\n        'grant_type' : 'refresh_token',\n        'client_id' : CLIENT_ID,\n        'client_secret' : CLIENT_SECRET,\n        'refresh_token' : REFRESH_TOKEN\n    } \n\n    headers = {'Content-Type' : 'application\/x-www-form-urlencoded;charset=utf-8'}\n\n    url = 'https:\/\/api.hubapi.com\/oauth\/v1\/token'\n    resp = requests.post(url, data = data, headers = headers)\n    return resp.json()\n\n\nif __name__ == '__main__': \n    app.run(debug=True)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Contact us for Hubspot Integration<\/h3>\n\n\n\n<p>If you have a problem related to Hubspot integration that you want to solve &#8211; engage Dhruvsoft Hubspot team. <a href=\"https:\/\/www.dhruvsoft.com\/contact-us\/\">Contact us<\/a> for more information.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Hubspot? HubSpot is an all-in-one business automation tool that helps an Organization to attract clients, convert them into a lead and close the deal effectively bringing the best results for a business. It has been described as unique because it strives to provide its customers with an all-in-one approach.<\/p>\n","protected":false},"author":22,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[],"class_list":["post-677","post","type-post","status-publish","format-standard","hentry","category-technology","entry"],"_links":{"self":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts\/677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/comments?post=677"}],"version-history":[{"count":0,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts\/677\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/media?parent=677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/categories?post=677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/tags?post=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}