APIs & Integrations

sosv
Member

Missing or unknown grant type

SOLVE

Hi,

I am trying to obtain an access token via a node.js backend.

My code to do so looke like this:

sosv_0-1729450803517.png

 

I am gettin a 400 error: Missing or unknown grant type

 

Can you guide me in what I am doing wrong?

It works perfectly fine in curl and in Postman with the same data.

1 Accepted solution
sosv
Solution
Member

Missing or unknown grant type

SOLVE

Hi,

 

I made it work with the following code:

sosv_1-1729530172523.png

 

Looks like the qs.stringify is the trick here and changing form to data...

View solution in original post

0 Upvotes
4 Replies 4
GRajput
Recognized Expert | Platinum Partner
Recognized Expert | Platinum Partner

Missing or unknown grant type

SOLVE

Hi @sosv 

 

"There are some possibilities for that problem:

1. Check the redirect URL in both places (in the app and the code); the redirect URLs should be the same.
2. Ensure that the code is correct."

 

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


0 Upvotes
sosv
Member

Missing or unknown grant type

SOLVE

Hi @GRajput , thank you for your response. I have double checked the redirect URI and it is the same in the app settings and in the source code (im my example it is: localhost:3000/api/hubspot/callback). The code is also correct, if I try this using cURL, then it is working fine.

 

Any other pointers that might help me?

0 Upvotes
GRajput
Recognized Expert | Platinum Partner
Recognized Expert | Platinum Partner

Missing or unknown grant type

SOLVE

Hi @sosv 

Please try with the updated code. I think it will help you.

 

const axios = require('axios');
const qs = require('qs');
let data = qs.stringify({
  'grant_type': 'authorization_code',
  'code': 'string',          // Replace 'string' with the actual authorization code
  'redirect_uri': 'string',   // Replace 'string' with your actual redirect URI
  'client_id': 'string',      // Replace 'string' with your client ID
  'client_secret': 'string'   // Replace 'string' with your client secret
});
axios.post('https://api.hubapi.com/oauth/v1/token', data, {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  maxBodyLength: Infinity
})
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

 

 

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


0 Upvotes
sosv
Solution
Member

Missing or unknown grant type

SOLVE

Hi,

 

I made it work with the following code:

sosv_1-1729530172523.png

 

Looks like the qs.stringify is the trick here and changing form to data...

0 Upvotes