-
Notifications
You must be signed in to change notification settings - Fork 0
/
getContentById.py
48 lines (31 loc) · 1.04 KB
/
getContentById.py
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
import json
import requests
with open('./config.json', 'r') as f:
configData = json.load(f)
# api-endpoint
authURL = configData['authURLs']['authBaseURL']
# defining a params dict for the parameters to be sent to the API
jdata = configData['authData']
requestHeader = {
"Content-Type": "application/json"
}
# sending get request and saving the response as response object
r = requests.post(url = authURL+'/v2/token', json = jdata, headers=requestHeader)
print(r.status_code)
# extracting data in json format
data = r.json()
# extracting accesstoken and expiryTime
accessToken = data['access_token']
expiresIn = data['expires_in']
##########
newRequestId = '1351'
newRequestHeader = {
"Authorization":"Bearer "+accessToken,
"Content-Type": "application/json"
}
r2 = requests.get(url = configData['authURLs']['restBaseURL']+'/asset/v1/content/assets/'+newRequestId,headers=newRequestHeader)
# extracting data in json format
data = r2.json()
print(r2)
with open('./outputs/ContentData.json', 'w') as outfile:
json.dump(data, outfile)