Versions Compared


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


Java and API-NG

This page contains some code snippets of Java interaction with API-NG. This example shows how to use Java to send requests to list the event types, find the next horse racing market and then placing a bet with an invalid stake to trigger an error. The code referred to here is available at

In the sample code we use the json-rpc and rescript protocols. All requests are sent and received using json format. To post a request we prepare the json string using Java objects and then we serialize the object using the gson library. The example requests contain some predefined data that can be modified depends on user needs. 


This is a maven project containing Java sample code to connect to the Betfair API-NG application.
It requires:
  - Apache Maven 3
  - Java 7

How to run it

You first build the project with:
mvn clean package


example: mvn exec:java -Dexec.mainClass="com.betfair.aping.ApiNGDemo" -Dexec.args="myAppKey mySessionToken json-rpc"

An addition code snippets for Error Handling - non HTTP 200 responses is included below, but does not form part of the code included the the git repository.

Code Snippet

Creating the request - JSON-RPC