curl from DOS batch file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • decastroferro
    Junior Member
    • Aug 2016
    • 4

    #1

    curl from DOS batch file

    I am attempting to communicate with the betfair API. My day job is as a C programmer working under windows and my programming skill set is extremely narrow. A lot of the documentation is a complete mystery to me. I have tried and failed to write C code for the betfair API. I failed at the first hurdle - i.e. I couldn't even login.

    Plan B: it occurred to me that I could call curl from a DOS batch file. So I tried logging in by looking at these examples here:

    https://raw.githubusercontent.com/be...ript_curl.bash

    I guessed how to convert this bash script into DOS commands and came up with this:

    curl -q -k --cert c:\openssl\bin\client-2048.crt --key c:\openssl\bin\client-2048.key https://identitysso.betfair.com/api/certlogin -d "username=dXHIDDENXro&password=XHIDDENX" -H "X-Application: curlCommandLineTest

    Much to my amazement it worked and curl responded by outputting this:

    {"sessionToken":"I4jp3mGRvtTi4uXHIDDENXNNlAHAZ7THe KPFubwc=","loginStatus":"SUCCESS"}

    I'm assuming this session token be valid in this DOS box until I log out, or shut the DOS box. (correct me if I'm wrong)

    So all well and good but then I tried to get list_all_event_types working. I tried the following:

    set HOST=https://api.betfair.com/exchange/betting
    set SESSION_TOKEN=I4jp3mGRvtTi4uXHIDDENXNNlAHAZ7THeKPF ubwc=
    set APP_KEY=MakJHIDDEN8sbPIr
    curl -s -X POST --header "Accept: application/json" --header "Content-Type: application/json" --header "X-Application: %APP_KEY%" --header "X-Authentication: %SESSION_TOKEN%" --data "{\"filter\":{}}" %HOST%/rest/v1/listEventTypes/

    Sadly there appeared to be no reply from curl. No error message, the command prompt ">" came back again, and that was the end of that.

    Any ideas what I did wrong? Or how I can diagnose the problem?
  • SimonN
    Junior Member
    • Dec 2014
    • 71

    #2
    decastroferro,

    Unfortunately, I am unable to shed any light on the issue but I don't know what I would have done trying to get the right syntax to verify my OpenSSL Certificate with CUrl without your example!!

    Couldnt believe my eyes when it came back with Login Success and the Session Token!

    So many thanks for that. Much appreciated.

    I am now probably in a similar situation as you were now though in trying to take it forward into the programming.

    Did you manage to get any joy in getting it to work in code?

    Did you see the sample code for non interative login?

    http://docs.developer.betfair.com/do...iveLoginSample

    That's my next stop apart from asking here further. As a general rule I find I get better responses on threads with more posts rather than starting fresh threads FYI.

    By the way, how long is it supposed to stay logged in?

    Cheers,

    Simon

    Edit: here's the Python - there's C Sharp as well but so much longer

    Sample Python code
    #!/usr/bin/env python

    import requests

    #openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key


    payload = 'username=myusername&password=password'
    headers = {'X-Application': 'SomeKey', 'Content-Type': 'application/x-www-form-urlencoded'}

    resp = requests.post('https://identitysso.betfair.com/api/certlogin', data=payload, cert=('client-2048.crt', 'client-2048.key'), headers=headers)

    if resp.status_code == 200:
    resp_json = resp.json()
    print resp_json['loginStatus']
    print resp_json['sessionToken']
    else:
    print "Request failed."
    Last edited by SimonN; 09-09-2016, 02:29 AM.

    Comment

    • SimonN
      Junior Member
      • Dec 2014
      • 71

      #3
      Worked first time using the Python script!

      Comment

      Working...
      X