I am trying to write a code in python which download only specific key value in the Calls.
So the solution might be
- Downloading the Raw data and later removing the unwanted through regex or 2)Applying specific process in API calls itself which downloads and appends only "Value".
Note - Code for access_token not included.
My Basic code from postman was
url = "https://xyz-stg.csod.com/services/api/x/odata/api/views/vw_rpt_performance_comment"payload={}
headers = {'Authorization': 'Bearer ' + access_token,'Cookie': 'ASP.NET_SessionId=hsylq0qqp; Cookie_2=value'
}response = requests.request("GET", url, headers=headers, data=payload).json()print(response, file=open(r"C:\Users\path\Desktop\Python script\output.json", 'w', encoding='utf-8', errors='ignore'))while response['@odata.nextLink']:url = response['@odata.nextLink']response = requests.request("GET", url, headers=headers, data=payload).json()#response.extend(response)print(response, file=open(r"C:\Users\path\Desktop\Python script\output.json", 'a', encoding='utf-8', errors='ignore'))break
Raw json output data
*{ "@odata.context": "https://example.com/services/api/x/odata/api/views/$metadata#vw_rpt_review_response_comment", "value": [ { "pr_comment_id": 1, "pr_comment": "Test Comment" }, { "pr_comment_id": 2, "pr_comment": "Test Comment" }, { "pr_comment_id": 3, "pr_comment": "Test Comment" } ],
"@odata.nextLink": "https://example.com/services/api/x/odata/api/views/$metadata#vw_rpt_review_response_comment?$skip=1000"
} { "@odata.context": "https://example.com/services/api/x/odata/api/views/$metadata#vw_rpt_review_response_comment", "value": [ { "pr_comment_id": 4, "pr_comment": "Test Comment" }, { "pr_comment_id": 5, "pr_comment": "Test Comment" }, { "pr_comment_id": 6, "pr_comment": "Test Comment" } ],
"@odata.nextLink": "https://example.com/services/api/x/odata/api/views/$metadata#vw_rpt_review_response_comment?$skip=2000"
}*
Beautify json
REQUIRED OUTPUT
*{ "value": [ { "pr_comment_id": 1, "pr_comment": "Test Comment" }, { "pr_comment_id": 2, "pr_comment": "Test Comment" }, { "pr_comment_id": 3, "pr_comment": "Test Comment" } , { "pr_comment_id": 4, "pr_comment": "Test Comment" }, { "pr_comment_id": 5, "pr_comment": "Test Comment" }, { "pr_comment_id": 6, "pr_comment": "Test Comment" } ]
}*
Beautify json