Scope Error when testing auth with integration

I am getting an error with my application right now and am unable to authenticate while testing due to an error that reads:

“Couldn’t complete connection. Authorization failed because the provided scopes are insufficient. Please contact the app developer.”

Thiis is my application:

https://app.hubspot.com/developer/46358881/application/3405307

Here is the code we are using to authenticate:

@NS_api.route('/hubspot')
class HubspotResource(Resource):
 @Api.doc(security=None, responses={200: 'Success', 401: 'Failed to get Hubspot token'}, description='Hubspot OAuth endpoint', params={'organization_id': 'Organization ID'})
 @handle_exceptions
 def get(self):
 # SCOPES must match the scopes in the Hubspot app
 HUBSPOT_SCOPES = ['crm.objects.contacts.read', 'crm.objects.contacts.write',
 'crm.objects.deals.read','crm.objects.deals.write','oauth']
 CLIENT_ID = os.getenv("HUBSPOT_CLIENT_ID")
 organization_id = request.args.get("organization_id")
 if organization_id:
 encoded_org_id = encode_entity_id(organization_id)
 org_param = f"&leadoff_state={encoded_org_id}"
 else:
 org_param = ""
 oauth = OAuth2Session(CLIENT_ID, scope=HUBSPOT_SCOPES, redirect_uri=os.getenv("BASE_URL") + "/hubspot-callback")
 authorization_url, state = oauth.authorization_url('https://app.hubspot.com/oauth/authorize')
 return jsonify({"redirect_url": authorization_url + org_param})

Any idea why this is happening or how we can correct it?

Hey, @SMaliska :waving_hand: Thanks for your question. As an additional troubleshooting step, have you tried collecting and analyzing a HAR file? Occasionally, the full missing scopes error can be revealed this way.

Basic steps:

This doesn’t always reveal the issue, but it’s a good next step to try if you haven’t already done so.

Best,

Jaycee