...
...
...
...
...
Table of Contents |
---|
When & How to Use Vendor Services
There are two separate methods available to Vendors.
- Vendor Services API - Available to licensed software vendors who want to provide Betfair Exchange customers access to their certified software using a subscription based system.
- Vendor Web API - Available to licensed software vendors who want to develop web applications using the Betfair API for access by Betfair Exchange customers.
Vendor Services API
The Vendor Services API allows licensed and certified Software Vendors to manage the permissioning of Betfair accounts to their API-NG application/s.
With the Vendor Services API, you can:
...
Info |
---|
|
There are two key processes that Vendor will need to following when using the Vendor Services in API-NG:
Each of these processes are detailed below.
...
Preconditions:
- Customer has a Betfair account.
- Vendor has a Betfair vendor account, the App Key for their app, and their (Vendor) session token
Example flow:
...
...
In this scenario the Vendor wishes to check the customer’s subscription status to establish if the customer has:
- An existing active subscription.
- An expired subscription.
- A cancelled subscription.
- No current or previous subscription history (i.e. Customer is entirely new).
This can be done within the application itself (client side) or by Vendor on their app server (server side). Each process is explained in more detail below:
Client side process:
- Vendor’s app client requires Customer to login to Betfair using the Interactive Login method.
- Betfair returns Customer’s Session Token to the Vendor’s app client.
- Vendor’s app client calls getApplicationSubscriptionHistory citing Vendors App Key in the request body and the customer's Session Token in the X-Authentication header.
- Betfair returns Customer’s subscription history. If an empty list is returned then the customer has no current or previous subscription history (i.e. Customer is entirely new)
Server side process:
- Vendor’s app client requires Customer to login to Betfair using Interactive Login method.
- Betfair returns Customer’s Session Token to the Vendor’s app client.
- Vendor’s app client calls getVendorClientId citing Customer’s session token from step 1.
- Betfair returns Customer’s vendorClientId.
- Vendor’s App client sends Customer’s vendorClientId to Vendor’s app server.
- Vendor’s app server calls getApplicationSubscriptionHistory citing Vendor’s Session Token, Vendor’s App Key, and the vendorClientID from step 4.
- Betfair returns Customer’s complete history for the Vendor’s app (as identified by the app key cited in step 5). If an empty list is returned then the customer has no current or previous subscription history (i.e. Customer is entirely new).
Vendor Web API
The Vendor Web API is available to licensed Software Vendors who are creating web based applications These operations enable the web application to carry out operations on the users behalf using the OAuth2 protocol.
OAuth 2 Flow - Creating an Access Token
The user authentication via web apps is underpinned by the OAuth 2 protocol.
You will need to redirect the user to the Betfair login page (identitysso.betfair.com/view/vendor-login), along with up to three parameters:
...
Example call
The user will log in and be presented with a message asking them to allow you to perform Betfair calls on their behalf, as shown below.
Should they accept this message, they will be redirected to your site (using your redirect URL + any optional parameters). Critically, we will include an authorization codeas a parameter, under the parameter name "code".
NOTE: The authorization code will be valid for a single use for 10 minutes.
Example redirect
You will need to propagate this code to your back-end, from which you will have to exchange it for an access token. The access token will allow you to use the Betfair API on the user's behalf.
To obtain it, you will need to call the token operation on the Accounts API.
Example Token request
The token call takes the following parameters:
- Header: 'X-Application' : 'your app key'
- Header: 'X-Authentication' : 'your session token'
- client_id: your vendor ID
- grant_type: in this context, this will have to be set to 'AUTHORIZATION_CODE'
- code: the code you were returned
- client_secret: your secret, obtained from GetDeveloperAppKeys
And returns the following information:
...
IMPORTANT
To protect sensitive information such as your app key and secret, it is important that the token operation only be called from server to server.
Example call using REST
Example response
{ "access_token" : "KeOi+kyg2RvDK4HM+W46CvSnP5w=" , "refresh_token" : "50d76117-7f85-375v-a38f-ffb332713f93" , "application_subscription" :{ "vendor_client_id" : "456238" }, "token_type" : "BEARER" , "expires_in" : "14400" } |
OAuth 2 Flow - Using the Refresh Token
When the access token expires, it is possible to create a new one without any user input, using the refresh token. This is done with the same call that was used to create it originally, the token operation, but with a different set of parameters:
- Header: 'X-Application' : 'your app key'
- Header: 'X-Authentication' : 'your session token'
- client_id: your vendor ID
- grant_type: 'REFRESH_TOKEN'
- refresh_token: the refresh token for the user
- client_secret: your secret, obtained from GetDeveloperAppKeys
This will return the same information as the original call:
- access_token: the access token, used to call Betfair on the user's behalf
- token_type: meta data for the access token (see 'Making calls on the user's behalf')
- expires_in: how long the access token will be valid for (in seconds)
- refresh_token: the refresh token remains the same
- application_subscription: contains the vendor client ID, a unique identifier for a user
Example request using REST
Example response
{ "access_token" : "KeOi+kyg2RvDK4HM+W46CvSnP5w=" , "refresh_token" : "50d76117-7f85-375v-a38f-ffb332713f93" , "application_subscription" :{ "vendor_client_id" : "456238" }, "token_type" : "BEARER" , "expires_in" : "14400" } |
Making API Calls On The Users Behalf
Once you have an access token, you can start calling the Betfair API on the user's behalf based on their actions on your site.
You will need to populate headers in a different way to a standard API call:
- X-Application: your application key
- Authorization: token_type + " " + access_token
The Authorization header needs to be a concatenation of the token type and the access token (both returned by the token call), separated by a space.
Example:
Betfair will use the access token to determine which user the calls are being made for.
These calls also have to be from back-end to back-end.
User Revocation
...
Appanvil karma designer | ||||
---|---|---|---|---|
|
Table of Content Zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When & How to Use Vendor ServicesThere are two separate methods available to Vendors.
The Vendor Services API allows licensed and certified Software Vendors to manage the permissioning of Betfair accounts to their API-NG application/s. With the Vendor Services API, you can:
There are two key processes that Vendor will need to follow when using the Vendor Services in API-NG: Each of these processes is detailed below.
Preconditions:
Example flow:
In this scenario, the Vendor wishes to check the customer’s subscription status to establish if the customer has:
This can be done within the application itself (client side) or by Vendor on their app server (server side). Each process is explained in more detail below: Client side process:
Server side process:
The Vendor Web API is available to licensed Software Vendors who are creating web-based applications These operations enable the web application to carry out operations on the users behalf using the OAuth2 protocol. OperationsThe following operations are available via the Vendor Web API OAuth 2 Flow - Creating an Access TokenThe user authentication via web apps is underpinned by the OAuth 2 protocol. You will need to redirect the user to the Betfair login page (identitysso.betfair.com/view/vendor-login), along with up to three parameters:
Creating An Access Token - Betfair.com customers
Example redirect
Example Token RequestThe token call takes the following parameters: Request Headers
Request Body
Response Parameters
Example token request - REST
Example token request - JSON
OAuth 2 Flow - Using the Refresh TokenWhen the access token expires, it is possible to create a new one without any user input, using the refresh token. This is done with the same call that was used to create it originally, the token operation, but with a different set of parameters, for example, grant_type: REFRESH_TOKEN and refresh_token:
Header: 'X-Application' : 'your app key' Header: 'X-Authentication' : 'your session token' client_id: your vendor ID, obtained from /wiki/spaces/OL/pages/1671181 grant_type: 'REFRESH_TOKEN' refresh_token: the refresh token for the user client_secret: your secret, obtained from/wiki/spaces/OL/pages/1671181 This will return the same information as the original call: access_token: the access token, used to call Betfair on the user's behalf token_type: metadata for the access token (see 'Making calls on the user's behalf') expires_in: how long the access token will be valid for (in seconds) refresh_token: the refresh token remains the same application_subscription: contains the vendor client ID, a unique identifier for a user Example Refresh Token request - REST
Making API Calls On The Users BehalfOnce you have an access token, you can start calling the Betfair API on the user's behalf based on their actions on your site. You will need to populate headers in a different way to a standard API call: X-Application: your application key Authorization: token_type + " " + access_token The Authorization header needs to be a concatenation of the token type and the access token (both returned by the token call), separated by a space. Example: Betfair will use the access token to determine which user the calls are being made for. These calls also have to be from back-end to back-end.
User RevocationThe user may choose to revoke the permissions previously granted to your web application. You must provide the user with the facility to do so within any web app using the revokeAccessToWebApp operation. This will invalidate the access token and destroy your refresh token. Any subsequent calls to Betfair using the access token, or any attempt to generate a new one using the refresh token will result in either an INVALID_SESSION exception or UNEXPECTED_ERROR respectively. Example RevokeAccessToWebApp Request
Legacy SubscriptionsThe way subscriptions are handled for web applications |
...
differs greatly from the way they were for desktop-based applications. |
...
The subscription token model is no longer enforced, however, you may still choose to create and manage subscriptions using |
...
the existing |
...
Please note that in this model, Betfair will no |
...
longer prevent requests for a user with an expired or |
...
canceled subscription. You can choose what action to take based on information contained in the application_subscription field returned by the token operation. The available operations are the following: |
...
If you do use these calls to manage subscriptions, the token call will return information on the most relevant subscription (i.e. the subscription with the latest expiration date) as part of the application_subscription object. Flow Diagram |
...
Sample CodeSample code that demonstrates the web apps interaction is available via https://github.com/betfair/sample-web-app-vendor/ |
...
|