Ball by Ball Push via Webhook
Ball by Ball Push via Webhook
Get real-time notifications for ball updates and corrections. Call the Ball by Ball API for detailed delivery information.
Configuring your Console
Follow the instructions below to receive automated cricket match updates in your Webhook URL.
- Login to your Roanuz Sports Console and from the Dashboard, click on Push Configuration and select the Webhook Option.
- Now, in the text boxes, paste your Webhook URLs to which you want the data to be delivered automatically.
- Make sure to set up your webhook URL to handle the data correctly. A sample code has been provided under the “Handling the data received” section.
Scenarios
After configuring your console, this section details the notifications from the Ball by Ball Push API. It explains the types of updates you’ll receive, whether they relate to ball events or other match changes. For specific ball details, you’ll need to use the Ball by Ball API.
1. Non-Ball Match Update
Technical Explanation:
When a match update occurs that isn't related to a ball (e.g., toss or squad changes), you'll receive a notification with the ball field as null. The push reason will be "Other" and the match_push_kind will also be "Other."
Non-Technical Explanation:
If something other than a ball changes in the match, like the toss or a squad update, you’ll get notified that something happened, but it won’t specify what.
Non-Ball Match Update
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": null,
"push_reason": "Other",
"match_push_kind": "Other",
"ts": 1234567890
}
}
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": null,
"push_reason": "Other",
"match_push_kind": "Other",
"ts": 1234567890
}
}
2. New Ball Entered
Technical Explanation:
When a new ball is delivered, the notification will include the ball details, such as ball_key, over, and batting_order. The push_reason will be "NewOrLast" and the match_push_kind will be "Ball."
Non-Technical Explanation:
Each time a new ball is bowled, you’ll get notified with details like the over and batting order, but it won’t show the ball’s result (like runs or wickets).
2. New Ball Entered
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": {"ball_key": 1049280, "over": 1, "batting_order": 2, "is_delete": false},
"push_reason": "NewOrLast",
"match_push_kind": "Ball",
"ts": 1234567890
}
}
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": {"ball_key": 1049280, "over": 1, "batting_order": 2, "is_delete": false},
"push_reason": "NewOrLast",
"match_push_kind": "Ball",
"ts": 1234567890
}
}
3. Ball Updated (Not Last Ball)
Technical Explanation:
If an earlier ball in the match is updated (e.g., umpire correction), the notification will include the ball's details, and the push_reason will be "Update" with match_push_kind as "Ball."
Non-Technical Explanation:
If an earlier ball is changed, you’ll get notified that it was updated, but it won’t tell you what exactly was changed.
3. Ball Updated (Not Last Ball)
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": {"ball_key": 1049280, "over": 1, "batting_order": 2, "is_delete": false},
"push_reason": "Update",
"match_push_kind": "Ball",
"ts": 1234567890
}
}
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": {"ball_key": 1049280, "over": 1, "batting_order": 2, "is_delete": false},
"push_reason": "Update",
"match_push_kind": "Ball",
"ts": 1234567890
}
}
4. Ball Deleted
Technical Explanation:
When a ball (either the last ball or an earlier one) is deleted, you’ll receive a notification where is_delete is true and the push_reason is "Other."
Non-Technical Explanation:
If a ball is removed from the match (for example, due to an error), you’ll get notified that a ball was deleted.
4. Ball Deleted
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": {"ball_key": 1049280, "over": 1, "batting_order": 2, "is_delete": true},
"push_reason": "Other",
"match_push_kind": "Ball",
"ts": 1234567890
}
}
{
"sport": "cricket",
"data_kind": "match-related-update",
"data": {
"matchkey": "matchkey",
"ball": {"ball_key": 1049280, "over": 1, "batting_order": 2, "is_delete": true},
"push_reason": "Other",
"match_push_kind": "Ball",
"ts": 1234567890
}
}
Subscription Type
You can subscribe to the Update Subscription, which ensures that the match data has been confirmed and cached, providing high-assurance updates for each ball and any match changes.
Update Subscription
- Trigger: When the match data is confirmed and cached.
- Notification: You’ll get a notification only after the ball data is confirmed as updated and recached. This is ideal for high-traffic or high-importance matches.
- Data Type:
match-related-update
Ball by Ball Push - Updates Subscribe
TERMINAL
pip install requests
pip install requests
ball_by_ball_updates.py
import requests
project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/match/{}/updates-subscribe/".format(project_key,match_key)
headers = {
'rs-token': token
}
payload = {
'method': "web_hook"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
import requests
project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/match/{}/updates-subscribe/".format(project_key,match_key)
headers = {
'rs-token': token
}
payload = {
'method': "web_hook"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
Handle the data received
Once successfully set up, Roanuz Cricket API servers will automatically start pushing data to your systems as the match progresses. The sample snippet below demonstrates how to handle the data once it is pushed by the server.
TERMINAL
pip install flask
pip install flask
webhook_handle_data.py
from flask import Flask, request
import gzip
import io
import json
app = Flask(__name__)
@app.route('/', methods=['POST'])
def hello():
print("Received")
c_data = io.BytesIO(request.data)
text_data = gzip.GzipFile(fileobj=c_data, mode='r')
byte_str = text_data.read()
dict_str = byte_str.decode("UTF-8")
mydata = json.loads(dict_str)
print(mydata)
print("____")
return 'Hello, World! {}'
from flask import Flask, request
import gzip
import io
import json
app = Flask(__name__)
@app.route('/', methods=['POST'])
def hello():
print("Received")
c_data = io.BytesIO(request.data)
text_data = gzip.GzipFile(fileobj=c_data, mode='r')
byte_str = text_data.read()
dict_str = byte_str.decode("UTF-8")
mydata = json.loads(dict_str)
print(mydata)
print("____")
return 'Hello, World! {}'
Unsubscribe from Ball by Ball Push
If, for any reason, you wish to opt-out of automatic push updates for the Ball by Ball notifications, you can easily unsubscribe.
Ball by Ball Push - Unsubscribe
TERMINAL
pip install requests
pip install requests
ball_by_ball_updates_unsubscribe.py
import requests
project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/match/{}/updates-unsubscribe/".format(project_key,match_key)
headers = {
'rs-token': token
}
payload = {
'method': "web_hook"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
import requests
project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/match/{}/updates-unsubscribe/".format(project_key,match_key)
headers = {
'rs-token': token
}
payload = {
'method': "web_hook"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())