How to Execute a POST to TD Ameritrade For OAUTH2 Authentication RRS feed

  • Question

  • User-2004102533 posted

    I am using OAUTH2 for the first tme. Looking at TD Ameritrade developer site I created this POST

    using RestSharp;

    public void Post([FromBody]string value)
    /* using RestSharp; // https://www.nuget.org/packages/RestSharp/ */

    var client = new RestClient("https://api.tdameritrade.com/v1/oauth2/token");
    var request = new RestRequest(Method.POST);
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("content-type", "application/x-www-form-urlencoded");
    request.AddParameter("application/x-www-form-urlencoded", "grant_type=refresh_token&refresh_token= refreshToken&client_id = AMNEH3TKP@AMER.OAUTHAP", ParameterType.RequestBody);
    IRestResponse response = client.Execute(request);
    int FakeMAperiod = 10;

    Can I put this code in my GET statement as the front end executes the GET.  I do not think I can put a POST in the GET

    Thursday, August 29, 2019 10:24 PM


  • User1724605321 posted

    Hi DoctorWhoKnew ,

    You can send Get query with token header after getting access  token from your post token request :

    string url = string.Format("{0}batchs", MyUrl);
    RestClient client = new RestClient(url);
    RestRequest getRequest = new RestRequest(Method.GET);
    getRequest.AddHeader("Accept", "application/json");
    request.AddHeader("authorization", "Bearer " + _fireBaseService.AuthToken);
    getRequest.AddParameter("name", MyName, ParameterType.QueryString);
    IRestResponse getResponse = client.Execute(getRequest);

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 2, 2019 2:51 AM