'Unable to get token in Recharge { error: 'unsupported_grant_type' }

    const axios = require("axios");
    const BASE_URL = `https://www.admin.rechargeapps.com/oauth/token`
    var params = {
     code: "0xDEADBEEF",
     grant_type: "authorization_code",
     redirect_uri: "https://your_domain.com",
     client_id: "*********************"
   }
   let body = JSON.stringify(params)
   getCompatibility = () => axios({
     method: "POST",
     url: BASE_URL,
     data: body,
     headers: {
        "Content-Type": "application/json"
     },

    })

I tried this to get token from recharge but all am getting is data: { error: 'unsupported_grant_type' } is there anything I have missed here?



Solution 1:[1]

Hey you just need to change grant_type with "client_credentials":-

  const axios = require("axios");
    const BASE_URL = `https://www.admin.rechargeapps.com/oauth/token`
    var params = {
     code: "0xDEADBEEF",
     grant_type: "client_credentials",
     redirect_uri: "https://your_domain.com",
     client_id: "*********************"
   }
   let body = JSON.stringify(params)
   getCompatibility = () => axios({
     method: "POST",
     url: BASE_URL,
     data: body,
     headers: {
        "Content-Type": "application/json"
     },

    })
)

Thanks !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manoj Kumar