"BAD Authorization Code" issue


#1

We are facing problem with HubSpot API,Getting “BAD Auth Code” error.
We have gone through all forums and blogs to check if any one faced the same problem but didn’t get solution


#2

Hi @sameer01,

What endpoint are you making the request to, and how are you formatting your request? Can you share those details, and include the error response body?


#3

Hi Derek,

We are following links given below

There are 2 steps involved

  1.  Get the token to be able to POST to the hubspot api
    
  2.  Use the token above and make POST request to hubspot contacts api and send the user details.
    

We are failing at the 1st step. Unable to get the token required. We are getting the error as “BAD Authorization Code” . we have tried all option, forums and blog posts to get a solution.

Below is the Code format

public static function hubSpotAuthentication(){

              $ch = curl_init();



              curl_setopt($ch, CURLOPT_URL, "https://api.hubapi.com/oauth/v1/token");

              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

             curl_setopt($ch, CURLOPT_POSTDATA, "grant_type=authorization_code&user_id=research@mindfields.net.au&password=XXX&client_id=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&client_secret=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&redirect_uri=http://www.mindfields.net.au/&code=mindfield2182017");

    curl_setopt($ch, CURLOPT_POST, 1);

Thanks & Regards

Sameer Kulkarni


#4

Hi @sameer01,

Just to make sure that you and I are on the same page; is the value listed for the code parameter (mindfield2182017) a placeholder for the code parameter returned to your redirect URI when the user authorized your app? That code is obtained after the user authorizes your app, which the Initiate an Integeation with Oauth 2.0 article discusses.