Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

NameDescriptionSample
product(mandatory)The product for which the login page is used and on which the user will do the login; This should be your application key."IhDSui3ODdsdwo"
url (mandatory)The url to which the the browser should be redirected in case of a successful login. 
By default, https://www.betfair.com will be allowed but further URLs can be added upon agreement with Betfair.
https://www.betfair.com

 

Keep Alive

URL Definition

https://identitysso.betfair.com/api/keepAlive

The presence of the "Accept: application/json" header will signal that the service should respond with JSON and not an HTML page

Headers

Name
Description
Sample
Accept (mandatory)header that signals that the response should be returned as JSONapplication/json
X-Authentication (mandatory)header that represents the session token that needs to be keep aliveSession Token
X-Application (optional)header the Application Key used by the customer to identify the product.App Key

Response structure

 

Code Block
{
  "token":"<token_passed_as_header>",
  "product":"product_passed_as_header",
  "status":"<status>",
  "error":"<error>"
}

...

 

SUCCESS
FAIL

 

Error values

INPUT_VALIDATION_ERROR
INTERNAL_ERROR
NO_SESSION

 

Call sample

 

Code Block
# full request
curl -k -i -H "Accept: application/json" -H "X-Application: AppKey" -H "X-Authentication: <token>" https://identitysso.betfair.com/api/keepAlive

 

Logout

URL Definition

https://identitysso.betfair.com/api/logout

The presence of the "Accept: application/json" header will signal that the service should respond with JSON and not an HTML page

Headers
Name
Description
Sample
Accept (mandatory)Header that signals that the response should be returned as JSONapplication/json
X-Authentication (mandatory)Header that represents the session token that needs to be keep aliveSession Token
X-Application (optional)Header the Application Key used by the customer to identify the product.App Key

 

Response structure

 

Code Block
{
  "token":"<token_passed_as_header>",
  "product":"product_passed_as_header",
  "status":"<status>",
  "error":"<error>"
}

 

Status values

 

SUCCESS
FAIL

 

Error values

 

INPUT_VALIDATION_ERROR
INTERNAL_ERROR
NO_SESSION

 

Call sample

 

Code Block
# full request
curl -k -i -H "Accept: application/json" -H "X-Application: AppKey" -H "X-Authentication: <token>" https://identitysso.betfair.com/api/logout

 

Sample Code

A sample client, written in C#, is available to demonstrate this process on Github.  This is a C# project created under Visual Studio 2010, written against .Net 4, and is a Winforms Application.

The key steps demonstrated by this client are:

  • Embed identitysso.betfair.com into your application
  • Handle the login method and retrieval of a session token from the cookies
  • Handle the keep alive method
  • Handle the logout method

How it works

Upon start-up, the URL of the API login page is assigned to the web browser control:

Code Block
//Give embedded web browser Betfair api login page URL         

System.Uri u = new Uri(LogonURL);

When the web browser control receives data an event is triggered and the following function called: 

Code Block
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
            //On embeded web browser response get cookie
            string cookie = this.webBrowser1.Document.Cookie;

            if (cookie != null)
                this.ParseCookie(cookie);

            //If successfull login start KeepAlive 
            if (!m_LoggedOut && !m_KeepAliveTimer.Enabled)
            {
                webBrowser1.Visible = false;
                SetMessage("Logon successfull\r\n SSOID=" + m_SSOID);

                
                this.StartKeepAlive();
            }
}

Upon successful login the cookie is parsed for the SSOID. The webrowser control made invisible and the SSOID displayed in a TextBox. The keep-alive timer is started

Code Block
private void StartKeepAlive()
	{            
            m_KeepAliveTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnKeepAliveTimer);
            // Set the Interval to 15 mins.
            m_KeepAliveTimer.Interval = 1000 * 60 * 15;
            m_KeepAliveTimer.Enabled = true;
        }

Above the StartKeepAlive function simply starts a 15 minute timer which invokes function OnKeepAliveTimer. 

OnKeepAliveTimer sends a Keep Alive message.

A message to this effect is then displayed.

Upon hitting the Logout button the following event handler is invoked:

Code Block
private void btnLogout_Click(object sender, EventArgs e)
        {
            m_KeepAliveTimer.Enabled = false;
            m_KeepAliveTimer.Close();
            m_LoggedOut = true;

            System.Uri u = new Uri(LogoutURL);
            this.webBrowser1.Url = u;
            this.webBrowser1.Navigate(u);

            SetMessage("Logged out");

        }

 

The keep alive timer is closed. The logout url is sent and a Logged out message is displayed.