OAUTH for Creating server only integration to API for exporting to our data warehouse

I’ve read a few posts talking about server integration with OAUTH, but they are all a bit lacking in a complete documentation. I don’t have a web server for this app. It’s just a series of python scripts. I just want to replace the API key with using OAUTH. I’m using Python. The other posts talk about using a web app to get the first authorization code. Isn’t there a simpler way? Does any have a simple example that fakes out the need for a real web app?

Hey @aressler,

When looking to initate the OAuth connection, your team would have to first create an app in a HubSpot developer account.

Can I clarify if your team has done that?

I did get it to work. In case this helps others, I did create an app in your portal. I then created a simple localhost web site with python flask. I was able to run it locally without SSL. The doc makes it seem that you need a real web site.

Here’s a sample python flask controller.

from flask import Blueprint, render_templatefrom flask import request, redirectimport jsonfrom .oauth_form import OauthFormimport urllib.parseimport tracebackhome_blueprint = Blueprint('home', __name__, template_folder='templates')@home_blueprint.route('/hubspot_oauth')def hubspot_oauth(): CLIENT_ID = urllib.parse.quote_plus(YOURCLIENTID) REDIRECT_URI = urllib.parse.quote_plus("http://localhost:8083/oauth_redirect") SCOPES = urllib.parse.quote_plus("contacts content reports social automation transactional-email integration-sync tickets e-commerce crm.objects.marketing_events.read crm.schemas.custom.read crm.objects.custom.read sales-email-read forms-uploaded-files") auth_url = """https://app.hubspot.com/oauth/authorize?client_id=%s&scope=%s&redirect_uri=%s"""%(CLIENT_ID, SCOPES, REDIRECT_URI) return redirect(auth_url, code=302)@home_blueprint.route('/oauth_redirect')def hubspot_oauth_redirect(): code = request.args.get("code") form = OauthForm() form.code.data = code url = "https://api.hubapi.com/oauth/v1/token" ClientID = 'YOURCLIENTID' ClientSecret = 'YOURCLIENTSECRET' REDIRECT_URI = 'http://localhost:8083/oauth_redirect' # same URL as above formData = { "grant_type": 'authorization_code', "client_id": ClientID, "client_secret": ClientSecret, "redirect_uri": REDIRECT_URI, "code": code } data = urllib.parse.urlencode(formData) data = data.encode('ascii') req = urllib.request.Request(url, data, method='POST') access_token = None refresh_token = None with urllib.request.urlopen(req) as response: data = None try: data = response.read() parsed_data = json.loads(data) access_token = parsed_data.get("access_token") refresh_token = parsed_data.get("refresh_token") except: traceback.print_exc() form.access_token.data = access_token form.refresh_token.data = refresh_token return render_template('oauth.html', form=form)