0

For authorization at DRchrono, I had created a GET request at https://drchrono.com/o/authorize/ with a redirect URL and clientId, as soon as I click on authorize I redirect to my redirect URL with code value in params,

then I made a POST request on https://drchrono.com/o/token/ via postman with this

{
"code":"x4xzqXXjlBWeeQxEzjyE8thFTIW0eT",
"grant_type": "authorization_code",
"redirect_uri": "",
"client_id": " ",
"client_secret": ""
}

client_id and client_secret value taken from DrChrono API management page. After making a post instead of getting the access token, I get "400 bad requests" in response. I am not getting what that thing I am missing.

for doing all this thing I followed DRchrono official document : https://drchrono.com/api-docs/v4?application=4217#section/Authorization/Initial-authorization

Can anyone help me with this??

Laurel
  • 5,965
  • 14
  • 31
  • 57
shivani
  • 1
  • 1
  • 5

1 Answers1

0

My issue got resolved by making these 2 changes:

  1. while making the post request we have to pass Content-Type=application/x-www-form-urlencoded in header
const Header = {
    "Content-Type": "application/x-www-form-urlencoded",
  };
  1. we also need to convert our json object into x-www-form-urlencoded, like this:
var postData = { 
    code:query.code,
    grant_type: "authorization_code",
    redirect_uri: " ",
    client_id: " ",
    client_secret: " ",
   };
   
var encodedData = "";
for (key in postData) {
        encodedData += encodeURIComponent(key)+"="+encodeURIComponent(postData[key])+"&";
 }

and then finally pass Header, encodedData value in post request

request.post("https://drchrono.com/o/token/", (data = encodedData), {
      headers: Header,
    }) .then((res) => {
      console.log("RESPONSE RECEIVED: ", res.data);
})

This article helped me for testing the Authentication from postman: http://drchronoapi.wpengine.com/connecting-to-drchronos-api-via-postman/

Hope this helps to others who faced similar issue :)

shivani
  • 1
  • 1
  • 5