Fantasy Match Points - via Webhook
Fantasy Match Points - via Webhook
Fantasy player points information available through the Fantasy Match Points API, 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:
- Log in 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.
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 Fantasy Match Points 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.
Fantasy Match Points Subscribe - Webhook
TERMINAL
pip install requests
pip install requests
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/{}/fantasy-match-points/{}/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/{}/fantasy-match-points/{}/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 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 Fantasy Match Points Unsubscribe API.
Fantasy Match Poitns Unsubscribe - Webhook
terminal
pip install requests
pip install requests
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/{}/fantasy-match-points/{}/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/{}/fantasy-match-points/{}/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())