<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Bad request (400) if made in my server in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495455#M24714</link>
    <description>&lt;P&gt;Hey! I am getting the same error when I try to get token through "&lt;A href="https://api.dropboxapi.com/oauth2/token" target="_blank" rel="noopener"&gt;https://api.dropboxapi.com/oauth2/token&lt;/A&gt;". It works in postman but when I try to access this route with header and request body with my node js website, it throws that error. I am not using Dropbox SDK for node. I am trying to replicate/learn from "nodegallerytutorial" posted on git, and in there I found this coode:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  //Exchange code for token
  if(req.query.code ){

  	let options={
  		url: config.DBX_API_DOMAIN + config.DBX_TOKEN_PATH, 
      //build query string
      qs: {'code': req.query.code, 
      'grant_type': 'authorization_code', 
      'client_id': config.DBX_APP_KEY, 
      'client_secret':config.DBX_APP_SECRET,
      'redirect_uri':config.OAUTH_REDIRECT_URL}, 
      method: 'POST',
      json: true 
    }

    try{

    	let response = await rp(options);

      //we will replace later cache with a proper storage
			//mycache.set("aTempTokenKey", response.access_token, 3600);
			await regenerateSessionAsync(req);
			req.session.token = response.access_token;

      res.redirect("/");

    }catch(error){
    	return next(new Error('error getting token. '+error.message));
    }        
  }
}&lt;/PRE&gt;
&lt;P&gt;promise-request is deprecated now, so I tired using node-fetch and axios. Here is code that I am using for the same path (the callback path I mentioned in my dropbox console).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;// here the version of the code that I used with axios
app.get("/callback", async (req,res)=&amp;gt;{
   
    try {
        const body = {
            grant_type: "authorization_code",
            code: req.query.code,
            redirect_uri: "http://localhost:3000/callback",
            client_id: client_id,
            client_secret: client_id,
            json:true
        };
     
      const response = axios.post("https://api.dropboxapi.com/oauth2/token", body);
      console.log({response});
      res.send({response});
    } catch(err)
    {
        res.send({error: err});
    }    
  
});



// below is the code for node-fetch that I used
app.get("/callback",  (req,res)=&amp;gt;{
  


        const body = {
            grant_type: "authorization_code",
            code: req.query.code,
            redirect_uri: "http://localhost:3000/callback",
            client_id: client_id,
            client_secret: client_secret
        
        };
        node_fetch("https://api.dropboxapi.com/oauth2/token", {
            method:'POST',
            body         
        }).then((response)=&amp;gt; response.json()).then((jsonObj)=&amp;gt;{
            res.send({response:jsonObj});
        }).catch((err)=&amp;gt;{
            res.send({err});
        });
});&lt;/PRE&gt;
&lt;P&gt;Here is the error. Please note that everything works fine when I use psotman.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="error.JPG" style="width: 858px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/20963i8724A8CE261556BD/image-size/large?v=v2&amp;amp;px=999" role="button" title="error.JPG" alt="error.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Feb 2021 21:30:06 GMT</pubDate>
    <dc:creator>someoneknew</dc:creator>
    <dc:date>2021-02-10T21:30:06Z</dc:date>
    <item>
      <title>Re: Bad request (400) if made in my server</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495455#M24714</link>
      <description>&lt;P&gt;Hey! I am getting the same error when I try to get token through "&lt;A href="https://api.dropboxapi.com/oauth2/token" target="_blank" rel="noopener"&gt;https://api.dropboxapi.com/oauth2/token&lt;/A&gt;". It works in postman but when I try to access this route with header and request body with my node js website, it throws that error. I am not using Dropbox SDK for node. I am trying to replicate/learn from "nodegallerytutorial" posted on git, and in there I found this coode:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  //Exchange code for token
  if(req.query.code ){

  	let options={
  		url: config.DBX_API_DOMAIN + config.DBX_TOKEN_PATH, 
      //build query string
      qs: {'code': req.query.code, 
      'grant_type': 'authorization_code', 
      'client_id': config.DBX_APP_KEY, 
      'client_secret':config.DBX_APP_SECRET,
      'redirect_uri':config.OAUTH_REDIRECT_URL}, 
      method: 'POST',
      json: true 
    }

    try{

    	let response = await rp(options);

      //we will replace later cache with a proper storage
			//mycache.set("aTempTokenKey", response.access_token, 3600);
			await regenerateSessionAsync(req);
			req.session.token = response.access_token;

      res.redirect("/");

    }catch(error){
    	return next(new Error('error getting token. '+error.message));
    }        
  }
}&lt;/PRE&gt;
&lt;P&gt;promise-request is deprecated now, so I tired using node-fetch and axios. Here is code that I am using for the same path (the callback path I mentioned in my dropbox console).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;// here the version of the code that I used with axios
app.get("/callback", async (req,res)=&amp;gt;{
   
    try {
        const body = {
            grant_type: "authorization_code",
            code: req.query.code,
            redirect_uri: "http://localhost:3000/callback",
            client_id: client_id,
            client_secret: client_id,
            json:true
        };
     
      const response = axios.post("https://api.dropboxapi.com/oauth2/token", body);
      console.log({response});
      res.send({response});
    } catch(err)
    {
        res.send({error: err});
    }    
  
});



// below is the code for node-fetch that I used
app.get("/callback",  (req,res)=&amp;gt;{
  


        const body = {
            grant_type: "authorization_code",
            code: req.query.code,
            redirect_uri: "http://localhost:3000/callback",
            client_id: client_id,
            client_secret: client_secret
        
        };
        node_fetch("https://api.dropboxapi.com/oauth2/token", {
            method:'POST',
            body         
        }).then((response)=&amp;gt; response.json()).then((jsonObj)=&amp;gt;{
            res.send({response:jsonObj});
        }).catch((err)=&amp;gt;{
            res.send({err});
        });
});&lt;/PRE&gt;
&lt;P&gt;Here is the error. Please note that everything works fine when I use psotman.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="error.JPG" style="width: 858px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/20963i8724A8CE261556BD/image-size/large?v=v2&amp;amp;px=999" role="button" title="error.JPG" alt="error.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 21:30:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495455#M24714</guid>
      <dc:creator>someoneknew</dc:creator>
      <dc:date>2021-02-10T21:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Bad request (400) if made in my server</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495525#M24715</link>
      <description>&lt;P&gt;[Cross-linking for reference:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/66144019/dropbox-400-error-while-trying-to-get-token-auth" target="_self"&gt;https://stackoverflow.com/questions/66144019/dropbox-400-error-while-trying-to-get-token-auth&lt;/A&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Dropbox API will return a more specific error message in the response body; print the full response&amp;nbsp;body to see the cause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically, an HTTP status 400 suggests that the body of the request is malformed - but the more specific message will help diagnose this.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 21:56:59 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495525#M24715</guid>
      <dc:creator>kylea</dc:creator>
      <dc:date>2021-02-10T21:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Bad request (400) if made in my server</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495588#M24718</link>
      <description>&lt;P&gt;Here is the full error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="full error json.JPG" style="width: 999px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/20976i05CCF58D8CEE8457/image-size/large?v=v2&amp;amp;px=999" role="button" title="full error json.JPG" alt="full error json.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 04:49:33 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495588#M24718</guid>
      <dc:creator>someoneknew</dc:creator>
      <dc:date>2021-02-11T04:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Bad request (400) if made in my server</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495771#M24725</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1410572"&gt;@someoneknew&lt;/a&gt;&amp;nbsp;Thanks for the additional information. This screenshot doesn't seem to show the actual response body from the&amp;nbsp;Dropbox API though. The "400" is just the status code of the response from the&amp;nbsp;Dropbox API, but the response would also contain a body, which isn't being shown here. You may need to check the documentation for the client you're using to see how you can print out the response body as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(In any case, it looks like you're sending the parameters as JSON, but the parameters for&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token" target="_self"&gt;/oauth2/token&lt;/A&gt; should be sent as&amp;nbsp;application/x-www-form-urlencoded POST parameters, not JSON.)&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 15:58:43 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Re-Bad-request-400-if-made-in-my-server/m-p/495771#M24725</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-02-11T15:58:43Z</dc:date>
    </item>
  </channel>
</rss>

