-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_script
More file actions
56 lines (34 loc) · 1.27 KB
/
Python_script
File metadata and controls
56 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import requests
import json
import time
import sys
from getpass import getpass
url = input("Enter your url: ")
#api_token = input("Enter your api_token: ")
api_token = getpass("Enter your api_token: ")
#url = sys.argv[1]
#api_token = sys.argv[2]
def send_request(url, method="GET", params=None, data=None, headers=None):
# Define custom headers
default_headers = {
'Authorization': f'APIToken {api_token}',
'Content-Type': 'application/json'
}
# Define the HTTP method and send the request
response = requests.request(method, url, params=params, data=data, headers=default_headers)
# Check if the response status code is OK (200)
if response.status_code == 200:
# Parse the response content as JSON
json_data = response.json()
return json_data
else:
print("Request failed with status code:", response.status_code)
xc_objects=send_request(url, method="GET")
# Extract all 'name' values from the 'items' list
xc_objects_names = [item['name'] for item in xc_objects.get('items', [])]
# Print or work with the array
print("Name Values:", xc_objects_names)
for xc_object_name in xc_objects_names:
xc_object=send_request(f"{url}/{xc_object_name}", method="GET")
print(xc_object)
time.sleep(1)