I am trying to create a Mathematica equivalent to the following code:
curl 'https://signin.tradestation.com/oauth/token' \
--request POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--data 'grant_type=authorization_code' \
--data 'client_id=XXXXXXXXX' \
--data 'client_secret=XXXXXXXXX' \
--data 'redirect_uri=http://localhost' \
--data 'code=XXXXXXXXX'
curl 'https://signin.tradestation.com/oauth/token' \
--request POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-raw 'grant_type=authorization_code&client_id=XXXXXXXXX&client_secret=XXXXXXXXX&redirect_uri=http://localhost&code=XXXXXXXXX'
My Wolfram Language code equivalent looks like this:
urlToken = "https://signin.tradestation.com/oauth/token";
headers = {"Content-Type" -> "application/x-www-form-urlencoded"};
parameters = {"grant_type" -> "authorization_code",
"client_id" -> apiKey, "client_secret" -> clientSecret,
"code" -> AuthCode, "redirect_uri" -> urlRedirect };
request =
HTTPRequest[
urlToken, <|"Method" -> "POST", "Headers" -> headers,
"Body" -> URLQueryEncode[parameters], "VerifyPeer" -> False|>];
response = URLRead[request]
Unfortunately all this produces is:
HTTPResponse[403 Status:Forbidden]
Can anyone advise what I am doing wrong?
Is there an easier approach?
request = HTTPRequest[urlToken, <|"Body" -> parameters|>]
? Does usingcurl
works as expected? Also, what is the body of the response:response["Body"]
? $\endgroup$Method
option is documented to be used without the quotes (it is a symbol, not a string). $\endgroup$