Match - via Webhook

Match - via Webhook

Match information available through the Match API endpoint, automatically updated and delivered to your Webhook URL in real-time.

Configuring your Console

Follow the instructions below to receive automated cricket match updates in your Webhook URL.
  1. Login to your Roanuz Sports Console and from the Dashboard, click on Push Configuration and select the Webhook Option.
  2. Now, in the text boxes, paste your Webhook URLs to which you want the data to be delivered automatically.
  3. 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.

Send a Subscription Request

Once your console is set up, you will have to subscribe to the matches individually for receiving automatic updates. The sample snippet below demonstrates how to send a subscription request from the Match Subscribe API. Please note that subscribing twice to the same match does not mean that you will be charged twice, or you will receive the same update twice.

Match Subscribe - Webhook

terminal
pip install requests
pip install requests
icon copy
Python
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/{}/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/{}/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())
icon copy

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
icon copy
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! {}'
icon copy

Unsubscribe from a Match

For any reasons, if you wish to opt-out of automatic updates for a match, you can do so by placing an unsubscribe request from the Match Unsubscribe API.

Match Unsubscribe - Webhook

TERMINAL
pip install requests
pip install requests
icon copy
match_unsubscribe_webhook.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/{}/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/{}/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())
icon copy