I have data from an application that I am making an API call from. I need the script to make the api call, save and parse the JSON data, check to determine if the value of one of the fields matches, and save it to a csv file in the below format.
print(RPS + ' ' + Hostname + ' ' + Serial_Number + ' ' + Group_Name + ' ' + Resource_Type + ' ' + Make + ' ' + Model + ' ' + Datacenter)
WHERE
RPS = device['asset_tag']
Hostname = device['name']
Serial_Number = device['serial']
Group_Name = device['tenant']['name']
Resource_Type = device['device_role']['name']
Make = device['device_type']['manufacturer']['name']
Model = device['device_type']['model']
Datacenter = device['site']['name']
Sample Data
"id": 10766,
"url": "http://application URL",
"display": "aix505vm1 (11920)",
"name": "aix505vm1",
"device_type": {
"id": 929,
"url": "http://application URL",
"display": "9115-505",
"manufacturer": {
"id": 11,
"url": "http://application URL",
"display": "IBM",
"name": "IBM",
"slug": "ibm"
},
"model": "9115-505",
"slug": "9115-505"
},
"device_role": {
"id": 51,
"url": "http://application URL",
"display": "Server",
"name": "Server",
"slug": "server"
},
"tenant": {
"id": 34,
"url": "http://application URL",
"display": "infosec Prod",
"name": "Infosec Prod",
"slug": "infosec-prod"
},
"platform": null,
"serial": "10-0CC5A",
"asset_tag": "11920",
"site": {
"id": 5,
"url": "http://application URL",
"display": "Data Hall 3 - Production",
"name": "Data Hall 3 - Production",
"slug": "data-hall-3-production"
},
"location": {
"id": 36,
"url": "http://application URL",
"display": "J",
"name": "J",
"slug": "j",
"_depth": 0
},
"rack": {
"id": 953,
"url": "http://application URL",
"display": "J28",
"name": "J28"
},
"position": 5,
"face": {
"value": "front",
"label": "Front"
},
"parent_device": null,
"status": {
"value": "active",
"label": "Active"
},
"airflow": null,
"primary_ip": null,
"primary_ip4": null,
"primary_ip6": null,
"cluster": null,
"virtual_chassis": null,
"vc_position": null,
"vc_priority": null,
"comments": "AIX 6.1 Build server. ",
"local_context_data": null,
"tags": [],
"custom_fields": {
"contract_start_date": "2020-05-15",
"contract_end_date": "2022-04-30",
"aptare_status": "Enabled",
"deployment_ticket": null,
"hardware_support_vendor": null,
"logistics_tag": null,
"ownership": "Owned",
"po_number": null,
"purchase_date": null,
"service_contract": "No Service_ 2020-05-15 to 2022-04-30",
"service_contract_notes": "Under contract",
"sr_entry_date": "2006-03-29"
},
"config_context": {},
"created": "2021-06-01T00:00:00Z",
"last_updated": "2021-06-01T18:12:26.940882Z"
}
]
}