paypal authorization unsupported_grant_type Grant Type is NULL in axios post request

Viewed 1097

I am trying to integrate paypal in my app and i got 400 error [unsupported_grant_type] Grant Type is NULL

axios
      .post(
        'https://api.sandbox.paypal.com/v1/oauth2/token',
        { grant_type: 'client_credentials' },
        {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          },
          auth: {
            username:
              'clientId',
            password:
              'secret'
          }
        }
      )
      .then(response => {
        console.log('response', response.data);

      })
      .catch(err => {
        // console.log('error', { ...err });
        console.log('error', err);
      });

what i am doing wrong?

Note: it works fine in postman

1 Answers

I found the solution..

stringify the body..

add

const qs = require('querystring');
qs.stringify({ grant_type: 'client_credentials' })
Related