400 Bad Request when getting access token for ExactOnline using RestSharp
<p>I need to go through the OAuth2 flow for ExactOnline but I get stuck on step 3 of the docs (<a href="https://developers.exactonline.com/#OAuth_Tutorial.html%3FTocPath%3DAuthentication%7C_____2" rel="nofollow">https://developers.exactonline.com/#OAuth_Tutorial.html%3FTocPath%3DAuthentication%7C_____2</a>)</p>

<p>I created the following c# code using the Postman chrome app for testing http requests but keep getting 400 errors (bad request). The postman app also gave me 400 errors but no matter what settings I set, I always seem to get a 400 error.</p>

<pre><code>var authToken = "veryyyyyylongtoken";
var redirectUri = "the-url-I-set-in-the-dashboard";
var grantType = "authorization_code";
var clientId = "id-guid";
var clientSecret = "secret";
var exactAccesTokenRequestEndpoint = "https://start.exactonline.nl/api/oauth2/token";

var client = new RestClient(exactAccesTokenRequestEndpoint);
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", String.Format("code={0}&amp;redirect_uri={1}&amp;grant_type={2}&amp;client_id={3}&amp;client_secret={4}", authToken, exactAccesTokenRequestEndpoint, grantType, clientId, clientSecret), ParameterType.RequestBody);
var response = client.Execute(request);
</code></pre>

<p>How is this code wrong?</p>

<p>The app registered at Exact is running in test mode, not production.</p>

<p>Any ideas?</p>

<p>===== EDIT =====</p>

<p>Based on Gusman's pointers I changed the code to the following. This still give a 400 error.</p>

<pre><code>var client = new RestClient(exactAccesTokenRequestEndpoint);
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("code", authToken, ParameterType.RequestBody);
request.AddParameter("redirect_uri", redirectUri, ParameterType.RequestBody);
request.AddParameter("grant_type", grantType, ParameterType.RequestBody);
request.AddParameter("client_id", clientId, ParameterType.RequestBody);
request.AddParameter("client_secret", clientSecret, ParameterType.RequestBody);
var response = client.Execute(request);
</code></pre>