I’m trying to request a token from Hubspot, but I don’t really understand what I’m doing. I keep getting the ‘Bad Request’ message back and don’t understand what I’m doing wrong. One thing that can be wrong is that don’t send ‘code’ in the request, because I have no idea how to get it for my app. Am I just making the wrong call? The datastring I upload in the request is’ String.Format (“grant_type = authorization_code & client_id = {0} & client_secret = {1} & scope = contacts & redirect_uri = {2}”, _client_ID, _client_Secret, "https://api.hubapi.com/oauth/v1/token ") ’
Can someone tell me what to do?
Hi @MarcelVoets
The code is a critical part of this request and is a value that is captured as part of the OAuth process for your App. The OAuth flow should be the following:
- The application opens a browser to send the user to the HubSpot OAuth 2.0 server
- The user reviews the requested permissions, and grants access to the application
- The user is redirected back to the application with an authorization code in the query string
- The application sends a request to the OAuth 2.0 server to exchange the authorization code for an access token
As you can see from above, when integrating an App, you’ll begin by accessing the Auth URL which is setup via your Developer App, this will then redirect and ask you to confirm the Portal you’re integrating with. Once approved, you’ll redirect to the URL defined in the redirect_URI and you’ll see the code appended to the URL.
This can then be passed in your request for the Access Token. Take a look at our Quickstart guide for a better idea of how this flow works.
I hope this helps!
Thank you for the quick response.
I have now managed to retrieve data from HubSpot. But just to be sure to check if I did it right.
1. You request a Code once via the browser, where the code is then returned in the redirect_uri
2. You then request an access token and a refresh token, which you save together with the number of seconds that the access token is valid
3. With that access token you can then retrieve the data
4. If the access token has expired, you can use the refresh token to retrieve a new access token
Hi @MarcelVoets
That’s the correct process!
Great, thanks again for your help