PaulerMladenA66553 | 2023-10-09 19:13:37 UTC | #1
Just starting out with Python SDK, and I am a Python beginner as well.
Looking for a script that will allow me to export all call recording policies, along with the queues assigned to them into a neat csv file that can be further read and manipulated.
I've grabbed a basic script from the developer API page (see below), but I struggle what to do next with it. I know I'll have to cross the pagination bridge when I get to it, but at this point I'd be happy to figure out how to pull the queue IDs assigned to a policy.
I understand that the script below will generate an "api_response" object, but I am struggling to "grab" those queue IDs from this object.
Thanks!
import PureCloudPlatformClientV2 from PureCloudPlatformClientV2.rest import ApiException from pprint import pprint
Configure OAuth2 access token for authorization: PureCloud OAuth
PureCloudPlatformClientV2.configuration.accesstoken = 'youraccess_token'
or use getclientcredentialstoken(...), getsaml2bearertoken(...) or getcodeauthorizationtoken(...)
create an instance of the API class
api_instance = PureCloudPlatformClientV2.RecordingApi();
page_size = 25 # int | The total page size requested (optional) (default to 25) |
page_number = 1 # int | The page number requested (optional) (default to 1) |
sortby = 'sortby_example' # str | variable name requested to sort by (optional) |
expand = ['expand_example'] # list[str] | variable name requested by expand list (optional) |
nextpage = 'nextpage_example' # str | next page token (optional) |
previouspage = 'previouspage_example' # str | Previous page token (optional) |
name = 'name_example' # str | the policy name - used for filtering results in searches. (optional) |
enabled = True # bool | checks to see if policy is enabled - use enabled = true or enabled = false (optional) |
summary = False # bool | provides a less verbose response of policy lists. (optional) (default to False) |
has_errors = True # bool | provides a way to fetch all policies with errors or policies that do not have errors (optional) |
deletedaysthreshold = 56 # int | provides a way to fetch all policies with any actions having deleteDays exceeding the provided value (optional) |
try:
Gets media retention policy list with query options to filter on name and enabled.
apiresponse = apiinstance.getrecordingmediaretentionpolicies(pagesize=pagesize, pagenumber=pagenumber, sortby=sortby, expand=expand, nextpage=nextpage, previouspage=previouspage, name=name, enabled=enabled, summary=summary, haserrors=haserrors, deletedaysthreshold=deletedaysthreshold) pprint(apiresponse) except ApiException as e: print("Exception when calling RecordingApi->getrecording_mediaretentionpolicies: %s\n" % e)
PaulerMladenA66553 | 2023-10-11 13:29:18 UTC | #2
I've tried to drill down into the apiresponse, but I get an error message "Class 'PolicyEntityListing' does not define '_getitem_'... I wonder what other way can I use to drill down into the apiresponse and get the data that I need?
PaulerMladenA66553 | 2023-10-27 11:41:27 UTC | #3
There might be easier ways to do this, but I figured this one...
transform api response into a json content
content = apiresponse.tojson() json_content = json.loads(content)
Once you have the JSON format you can drill down into the entity to get more specific date, for example: policyname = (jsoncontent["entities"][index]["name"]) policyid = (jsoncontent["entities"][index]["id"]) queues = (jsoncontent["entities"][index]["mediapolicies"]["callpolicy"]["conditions"]["forqueues"])
Index would be the number of the entity within the policy API starting at 0.
Hopefully this helps someone.
system | 2023-11-27 11:40:29 UTC | #4
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 22435