Dec-28-2022, 09:53 AM
HI,
Newbie here.
Not sure whats wrong with this code.
If anyone could help.
Basically what i want is, once entered a name of a selection I would like to see its ID.
Newbie here.
Not sure whats wrong with this code.
If anyone could help.
Basically what i want is, once entered a name of a selection I would like to see its ID.
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 data to search for data = input("Enter the data to search for: ") # Make the request and store the response in a variable response_text = 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_text) # Search for the data in the response JSON object if data in response_json: print(f"ID for {data}: {response_json[data]}") else: print(f"{data} not found in the response JSON.")