how to use URLfetch for use with http post

I’m not very strong with http and urlfetch, but I’m trying to log in to my TD-Ameritrade account with urlfetch here is the API description:

How do I pass the parameters and how do call urlfetch? what is a content type http header?

Kay Herbert:

Try

URLFetch[
	"https://apis.tdameritrade.com/apps/300/LogIn?source=#sourceID#&version=#version number#",
	"Method" -> "Post",
	"Headers" -> {"Content-Type" -> "application/x-www-form-urlencoded"},
	"BodyData" -> "userid=#userid#&password=#password#&source=#sourceID#&version=#version number#\n\n",
	"Cookies" -> True,
	"VerifyPeer" -> True]

These variables are assigned by TD Ameritrade, hopefully you have them

  • userid=#userid#
  • password=#password#
  • source=#sourceID#
  • version=#version number#

Also assume you can fill in the proper Mathematica variables and re-work this starter code to work. So the #variable# should be replaced with the correct strings.

Hans

Thanks, that worked! Exactly what I was looking for. Where did you find the BodyData option?

The Options section of the Documentation located URLFetch—Wolfram Documentation
has “Body” as the option for the payload. I am using Mathematica version 10.0.2 and the local documentation has “BodyData” as the option for the payload. I would go with your local documentation ref/URLFetch. I did not find it per se though, the payload concept is part of most HTTP Request/Response client and server implementations.

I have version 10.1, cannot find BodyData but it works while Body does not.

There maybe an issue with the documentation.

From local documentation “BodyData” is there and works. The link in the previous post does say “Wolfram Language”?