import requests def check_mac_in_hardware(mac): response = requests.get("http://10.200.4.12:8888/snipe_api") response.raise_for_status() # raise error if request failed api_key = response.text.strip() # or response.json() if JSON returned url = f'https://computer.z31.it/api/v1/hardware?limit=5&search={mac}' headers = { 'accept': 'application/json', 'authorization': f'Bearer {api_key}', 'content-type': 'application/x-www-form-urlencoded' } response = requests.get(url, headers=headers) if response.status_code != 200: print(f"Error fetching data: HTTP {response.status_code}") exit(1) data = response.json() # Extract asset_tag from all rows asset_tags = [row.get('asset_tag', '') for row in data.get('rows', []) if row.get('asset_tag')] print(asset_tags) if asset_tags: print("Mac already exists in Snipe IT") else: print("Does not exist") exit(0) check_mac_in_hardware("c8:f7:50:7f:ee:ce")