Access Token Request – Opposite Problem

Access Token Requerst – Opposite Problem

I’m having a little trouble getting started. But it’s the opposite problem I see in other posts. Using Postman, I can easily and successfully Post to auth/accesstokenrequest, and get a correct response with tokens. But making the same request using basic syntax within Visual Studio 2022 (using c#)—which should be simple, I run into problems.

The first problem was an SSL issue: {“The remote certificate is invalid because of errors in the certificate chain: NotTimeValid”}

Since I didn’t see anything about SSL’s in the Tradovate documentation, I simply told the program to ignore SSL errors:

clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };

Now, I’m able to post and I get a 200 back, but I can’t get past this error: {“errorText”:“Incorrect username or password. Please try again.”}

Here’s a snippet of my code:

AccessTokenRequest tokenRequest = new AccessTokenRequest() //public class
{
name = myUsername,
password = myPassword,
appId = “Test App”,
appVersion = “1.0”,
deviceId = GetDeviceID(),
cid = “",
sec = "
*********”
};

//According to MS documentation, this should NOT be set in .NET 4.7+ framework (I’m targeting 8.0)
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.UseDefaultCredentials = true; //no impact using this command
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };

HttpClient client = new HttpClient(clientHandler);

client.BaseAddress = new Uri(Globals.baseUrl); //https://demo-api-d.tradovate.com/v1/

var json = JsonSerializer.Serialize(tokenRequest);
var content = new StringContent(json, Encoding.UTF8, “application/json”);
var response = client.PostAsync(“auth/accesstokenrequest”, content).Result;

if (response.IsSuccessStatusCode)
{
var responseContent = response.Content.ReadAsStringAsync().Result;
var AccessTokenResponse = JsonSerializer.Deserialize(responseContent);

Here the request string:
{“name”:““,“password”:””,“appId”:“Test App”,“appVersion”:“1.0”,“deviceId”:““,“cid”:”“,“sec”:”******”}

Am I doing something wrong, did I miss something, or could VS be doing something behind the scenes—like with the headers (which I checked)? I’m sure it’s something simple, but I am befuddled.

Alternatively, I could just get & use the token from Postman…

Thanks in advance for helping.