I want to get data using HTTPS from

POST https://developers.betfair.com/api.betfair.com/exchange/betting/json-rpc/v1 HTTP/1.1

using JSON

[{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEvents", "params": {"filter":{}}, "id": 1}]

I have to provide values for X-Application and X-Authentication ( which I have but are private for the account ).

I know that this can be done directly from Mathematica.

Which function should I use and where / how should I provide the URL, POST, X-Application, X-Authentication and JSON data.

Example code for a similar API would already be helpful, I guess.

  • 2
    $\begingroup$ I generally use URLFetch with the "Headers" and "Body" option. $\endgroup$ – chuy Feb 8 '16 at 21:31
  • $\begingroup$ @chuy - Ok. I did not know about all the options of URLFetch. Will look into that, I suppose that might work. $\endgroup$ – nilo de roock Feb 8 '16 at 21:52

This should do the trick if you fill in the appropriate authentication headers:

url = "https://developers.betfair.com/api.betfair.com/exchange/betting/json-rpc/v1";
json = "[{\"jsonrpc\": \"2.0\", \"method\": \"SportsAPING/v1.0/listEvents\", \"params\":  {\"filter\":{}}, \"id\": 1}]";

URLFetch[url, {"StatusCode", "Headers", "Content"}, 
         "Body" -> json, 
         Method -> "POST", 
         "Headers" -> {"X-Application" -> "Hello", 
                       "X-Authentication" -> "World"}
  • 1
    $\begingroup$ Feels weird to use a function named Fetch to do a Post, I think they messed up the naming. $\endgroup$ – M.R. Apr 5 '17 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.