Anyway this is in response to someone who wanted to return the selection ID when inputting the selection name:
Code: Select all
import json
import requests
def post_to_ba(endpoint, raw_json):
headers = {'Content-Type': 'application/json'}
response = requests.post(endpoint, data=raw_json, headers=headers)
return response.text
# Prompt the user for the selection name
selection_name = input("Enter the selection name you require the ID for: ")
# Make the request and store the response in a variable
response = post_to_ba("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE","SELECTION_IDS","SELECTION_NAMES"]}')
# Parse the response text as JSON
response_json = json.loads(response)
print(response_json)
selections = response_json['result']['markets'][0]['selections']
# Search for the selection
for selection in selections:
if selection['name'] == selection_name:
selection_id = selection['id']
print(f"Selection ID for {selection_name}: {selection_id}")
break
else:
print(f"{selection_name}, not found in the list of selections.")
You should get the grasp of it fairly quickly