Hubspot Access Token


#1

Hi All,
I am new to Hubspot developer . I need to integrate my application with Hubspot CRM. How could i get Access token and refresh token in java . What is the API and parameters for getting access token using OAuth 2.0


#2

To get access token you need to create app using HubSpot and then after you can use fiddler to get refresh token


#3

yes i have created app in hubspot, how could i get access token programatically in java, I have Initiated an Integration with Oauth 2.0 with the following Code

{
url = yamlConfig.getCrmHubspotApiUrlAuthorize();
uri = new URI(url + “?client_id=” + clientId + “scope=contacts” + “&redirect_uri=” + request.getScheme()
+ “://” + request.getServerName());
httpClient = new DefaultHttpClient();
httpGet = new HttpGet();
httpGet.setURI(uri);
HttpResponse httpResponse = httpClient.execute(httpGet);
InputStream responseContent = httpResponse.getEntity().getContent();
String accessTokenResult = AppUtil.convertStreamToString(responseContent);

Error After initiating Oauth 2.0 using

url = yamlConfig.getCrmHubspotApiUrl();
uri = new URI(url);
httpPost = new HttpPost();
httpPost.setURI(uri);
httpPost.setHeader(“Content-Type”, “application/x-www-form-urlencoded;charset=utf-8”);
List params = new ArrayList();
params.add(new BasicNameValuePair(“grant_type”, “authorization_code”));
params.add(new BasicNameValuePair(“client_id”, yamlConfig.getCrmClientId()));
params.add(new BasicNameValuePair(“client_secret”, yamlConfig.getCrmClientSecretKey()));
params.add(new BasicNameValuePair(“redirect_uri”, “https://” + request.getServerName()));
params.add(new BasicNameValuePair(“code”, AppUtil.getSaltString()));
httpPost.setEntity(new UrlEncodedFormEntity(params));
httpClient = new DefaultHttpClient();
HttpResponse oauthResponse = httpClient.execute(httpPost);

{“status”:“BAD_AUTH_CODE”,“message”:“missing or unknown auth code”,“correlationId”:“81291d4e-4231-4579-ba0f-1e34180ccf02”,“requestId”:“2f1a2f564554fb61ad9ec6958b058003”}


#4

I think you are running wrong code over there as you can see in your image client id and clientSecret id is not correct, please add correct and one and try, and one more thing to get refresh token if you authenticate with HubSpot app with portal id it wil only be valid for next 10min to generate refresh token


#5

i have handled them internally in rest method, have given it for testing purpose.


#6

{“status”:“BAD_REDIRECT_URI”,“message”:“missing or unknown redirect URI”,“correlationId”:“29c21daf-ea06-4542-87b9-874b70fb8a31”,“requestId”:“0f68f594071650b0c5ba29594120535b”} now i get is error @Laxmi_Narayan


#7

Hi @Vivek_Shankar_Sakrap,

That error generally occurs when the redirectUrl you’re including in the request to get access/refresh tokens doesn’t match up with the one you include when initiating the OAuth connection. The following article has some more details here:


Generate OAuth 2.0 Access Token Programatically