500 Internal Server Error when trying to get access and refresh token

Hi

I had the oauth process working till a fews weeks back - access and refresh tokens were getting updated. But, now if I try to get or refresh tokens I get 500 internal server error. I get the grant code for a new oauth but the subsequent access token generation fails.The same code was working a while back. What could be the reason?

Hi @Suryatapa , happy to take a look here. Can you clarify what step exactly you’re getting caught up on in the OAuth flow? It sounds like you’re getting the 500 error using this endpoint: Accounts Dashboard | HubSpot. If this is the case, can you please provide the following:

  • Your App ID
  • An example request that’s failing.
  • The full error response you’re getting from HubSpot’s servers.

Thank you!

Thank you for your reply.Please find the below information.

APP Id: 188139

Request Code:

RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add(“grant_type”,“authorization_code”);
map.add(“client_id”, MY_CLIENT_ID);
map.add(“client_secret”,MY_CLIENT_SECRET);
map.add(“redirect_uri”,“http://localhost:9090/api/v1/projects/newhubspotOauth2redirect");
map.add(“code”, RECEIVED_GRANT_CODE);

String url = “https://api.hubapi.com/oauth/v1/token”;
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
ResponseEntity<String> responseToken = restTemplate.exchange(url, HttpMethod.POST, request,String.class);

The last line throws the below error:

org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error

Hi @Suryatapa , that 500 error looks like it’s coming from your program. I’ll need to see an error coming from HubSpot’s servers in order to accurately diagnose the issue. It would also be helpful if I could get the raw request to HubSpot’s servers that’s causing the error. I won’t be able to do much just taking a look at your code without the ability to run it.

HubSpot errors follow the format of:

{
   status: 'error',
   message: MESSAGE HERE,
   correlationId: ID HERE,
   requestId: ID HERE
}

Thank you

I get the 500 internal error when I make the call using postman as well.

This is the error response:

{
“status”: “error”,
“message”: “internal error”,
“correlationId”: “9f174a19-ed9a-457d-98dd-9a2584848d51”,
“requestId”: “52ea86605f39eab7f585fb5ccc15747d”
}

Great, thanks! Which endpoint are you using? Can you provide the request that you’re making? Make sure you follow the 4 steps outlined here. An example of programmatic fetching of tokens can be found in the Oauth quickstart guide as well

https://app.hubspot.com/oauth/authorize?client_id=1342ad9b-b2b4-4ae5-a9f9-88e9b81a63e0&redirect_uri=http://localhost:9090/api/v1/projects/newhubspotOauth2redirect"&scope=contacts%20automation%20content%20business-intelligence%20e-commerce%20files%20forms%20hubdb%20integration-sync%20social%20tickets%20timeline%20actions%20reports

- This returns a grant code.

Then the grant code is set in the code i shared earlier to fetch the tokens from

https://api.hubapi.com/oauth/v1/token

And this process was working fine until it stopped working.

I am wondering if it is something to do with the test account that is logging in for authentication - maybe it exceeded its no of attempts or something like that.

Hi @Suryatapa , I’m able to reproduce the error with your app. I created another app in your Developer Account that I was able to connect to your test account successfully via OAuth. I’m not sure why that error is occurring at the moment. One working theory is that there were many authorization URLs created for this single app to attempt to connect to HubSpot which could have thrown it off. Is your app installed in any other accounts? If not, I’d suggest making another app in your developer account, and starting fresh.

Make sure that your redirect_uri in your authorization URL does not contain quotation marks.

Thanks a lot for all your help!!!