...
Info |
---|
Note: If the command line arguments for application key and session token are not provided then the script will prompt for application key and session token |
Code Snippets
Calling API-NG with JSON-RPC
...
protocol
method and param values need to be changed based on the required service operation.You can execute multiple service operation together with a single call using batch json-rpc call where you can correlate the responses with value of the id.
Code Block | ||
---|---|---|
| ||
URL = url = "https://api.betfair.com/exchange/betting/json-rpc/v1" jsonrpc_req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEventTypes", "params": {"filter":{ }}, "id": 1}' headers = {'X-Application': appKey, 'X-Authentication': sessionToken, 'content-type': 'application/json'} def callAping(jsonrpc_req): try: req = urllib2.Request(url, jsonrpc_req, headers) response = urllib2.urlopen(req) jsonResponse = response.read() return jsonResponse except urllib2.URLError: print 'Oops no service available at ' + str(url) exit() except urllib2.HTTPError: print 'Oops not a valid operation from the service ' + str(url) exit() |
Calling API-NG with Rescript protocol
Code Block | ||
---|---|---|
| ||
url = 'https://api.betfair.com/rest/v1.0/${operationName}/' headers = {'X-Application': appKey, 'X-Authentication': sessionToken, 'content-type': 'application/json', 'accept': 'application/json'} request = '{"filter":{"eventTypeIds":["7"],"marketCountries":["GB"],"marketStartTime":{"from":"2013-05-21T00:00:00Z"}},"sort":"FIRST_TO_START","maxResults":"1","marketProjection":["RUNNER_METADATA"]}' def callAping(url, request): try: req = urllib2.Request(url, request, headers) response = urllib2.urlopen(req) jsonResponse = response.read() return jsonResponse except urllib2.URLError: print 'Oops there is some issue with the request' exit() except urllib2.HTTPError: print 'Oops there is some issue with the request' + urllib2.HTTPError.getcode() exit() |
...