RestSharp RestClient Sends back 400 status while the Ameritrade web page sends back a 200 status RRS feed

  • Question

  • User-2004102533 posted

    I am using the following coded and getting an invalid_grant status 400 error

                string url = string.Format("https://api.tdameritrade.com/v1/oauth2/token");
                RestClient client = new RestClient(url);
                RestRequest postRequest = new RestRequest(Method.POST);
                postRequest.AddHeader("cache-control", "no-cache");
                postRequest.AddHeader("content-type", "application/x-www-form-urlencoded");
                postRequest.AddParameter("application/x-www-form-urlencoded", "grant_type=refresh_token&access_type=offline&refresh_token=kf6...E&client_id=AMNE...@AMER.OAUTHAP&redirect_uri=http://localhost", ParameterType.RequestBody);//, ParameterType.RequestBody)
                // execute the request
                IRestResponse response = client.Execute(postRequest);

    When I use https://developer.tdameritrade.com/authentication/apis/post/token-0 I get a status 200 with the same values as I use for postRequest.AddParameter

    Monday, December 30, 2019 3:05 PM

All replies

  • User-474980206 posted

    Your parameters don’t match. The test site uses several parameters with values, you send one parameter (application....) with a query string as its value. This won’t work. You need an AddParameter for each parameter. 

    Friday, January 3, 2020 2:20 AM