Connecting to API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PortfolioSports
    Junior Member
    • Jan 2015
    • 2

    #1

    Connecting to API

    Hi, I am having real problems connecting to the betfair api. I have spoken to support several times, but their responses are far from helpful.
    I have a simple initial test script that does return a success statement:
    import requests
    import json

    api_key = "your_api_key"

    # Base URL for the Betfair API
    base_url = "https://api.betfair.com/exchange/betting/rest/v1.0/"

    # Example endpoint
    endpoint = "listEventTypes/"

    # Set the request headers
    headers = {
    "X-Application": api_key,
    "Accept": "application/json"
    }

    # Make the API request
    response = requests.get(base_url + endpoint, headers=headers)

    # Check the response status code
    if response.status_code == 200:
    # Request successful
    data = response.json()

    # Save the response to a JSON file
    with open("api_response.json", "w") as json_file:
    json.dump(data, json_file, indent=4)

    # Save the response to a text file
    with open("api_response.txt", "w") as txt_file:
    txt_file.write(json.dumps(data, indent=4))

    print("API response saved to api_response.json and api_response.txt")
    else:
    # Request failed
    print("Request failed with status code:", response.status_code)

    # Save the error response to a JSON file
    with open("error_response.json", "w") as json_file:
    json.dump(response.json(), json_file, indent=4)

    # Save the error response to a text file
    with open("error_response.txt", "w") as txt_file:
    txt_file.write(json.dumps(response.json(), indent=4))

    print("Error response saved to error_response.json and error_response.txt")​but of course, this isn't using the certificate authorisation.

    When I try to connect using the certificate, I get client error messages.
    I have followed the instructions, have created certificates locally, created the client file precisely as stated, yet it will not connect.

    I find the getting started documentation quite unhelpful as it involves jumping from one tutorial to another, several times and often getting lost in the process.

    I am actually totally blind so these things are sometimes a bit TMI on these api tutorial pages, especially when the full process is spread over three or 4 different instructional guides.

    Is there a clear, step-by-step process described anywhere, maybe on a 3rd party site, that makes this whole process simpler?

    The error is pointing to the certicate, but having created it several times, I cannot seem to identify where the error is.

    If anyone has expertise at this and would resolve this initial connectivity error (at a fee of course) feel free to reach out to me directly using tonygrantim (at) gmail etc, thanks.
    Tony Grant
    Portfolio Sports
  • LetsGo
    Senior Member
    • Oct 2018
    • 112

    #2
    If you want to know about betfair api then join this slack group
    betcode-org.slack.com

    There are also many examples on github.com


    Last edited by LetsGo; 13-05-2024, 12:02 PM.

    Comment

    Working...
    X