Code examples can be found in the examples directory on GitHub
Also take a look at the unit tests in the tests directory.
Source: calling_users.py
.. literalinclude:: ../examples/calling_users.py :linenos:
Source: calling_users_async.py
.. literalinclude:: ../examples/calling_users_async.py :linenos:
Source: users_wo_devices.py
.. literalinclude:: ../examples/users_wo_devices.py :linenos:
This example start with the list of all calling users and then calls
:meth:`wxc_sdk.person_settings.forwarding.PersonForwardingApi.configure` for each user. To speed up things a
ThreadPoolExecutor
is used and all update operations are scheduled for execution by the thread pool.
Source: reset_call_forwarding.py
.. literalinclude:: ../examples/reset_call_forwarding.py :linenos:
Here we read a bunch of user email addresses from a CSV. The CSV as an ERROR column and we only want to consider users without errors.
For all these users a VM setting is updated and the results are written to a CSV for further processing.
Source: modify_voicemail.py
.. literalinclude:: ../examples/modify_voicemail.py :linenos:
This example uses the Calendarific API at https://calendarific.com/ to get a list of national US holidays and creates
a "National Holidays
" holiday schedule for all US locations with all these national holidays.
A rudimentary API implementation in calendarific.py
is used for the requests to https://calendarific.com/.
Calendarific APIs require all requests to be authenticated using an API key. You can sign up for a free account to get
a free API account key which then is read from environment variable CALENDARIFIC_KEY
.
Source: us_holidays.py
.. literalinclude:: ../examples/us_holidays.py :linenos:
This example uses the Calendarific API at https://calendarific.com/ to get a list of national US holidays and creates
a "National Holidays
" holiday schedule for all US locations with all these national holidays.
A rudimentary API implementation in calendarific.py
is used for the requests to https://calendarific.com/.
Calendarific APIs require all requests to be authenticated using an API key. You can sign up for a free account to get
a free API account key which then is read from environment variable CALENDARIFIC_KEY
.
Source: us_holidays_async.py
.. literalinclude:: ../examples/us_holidays_async.py :linenos:
A typical problem specifically when creating CLI scripts is how to obtain valid access tokens for the API operations. If your code wants to invoke Webex REST APIs on behalf of a user then an integration is needed. The concepts of integrations are explained at the "Integrations" page on developer.cisco.com.
This example code shows how an OAUth Grant flow for an integration can be initiated from a script by using the Python
webbrowser module and calling the open()
method with the authorization URL of a given integration to open that
URL in the system web browser. The user can then authenticate and grant access to the integration. In the last
step of a successful authorization flow the web browser is redirected to the redirect_url
of the
integration.
The example code starts a primitive web server serving GET requests to http://localhost:6001/redirect
.
This URL has to be the redirect URL of the integration you create under My Webex Apps on developer.webex.com.
The sample script reads the integration parameters from environment variables (TOKEN_INTEGRATION_CLIENT_ID
,
TOKEN_INTEGRATION_CLIENT_SECRET
, TOKEN_INTEGRATION_CLIENT_SCOPES
). These variables can also be defined in
get_tokens.env
in the current directory:
.. literalinclude:: ../examples/get_tokens.env (sample)
The sample code persists the tokens in get_tokens.yml
in the current directory. On startup the sample code tries
to read tokens from that file. If needed a new access token is obtained using the refresh token.
An OAuth flow is only initiated if no (valid) tokens could be read from get_tokens.yml
Source: get_tokens.py
.. literalinclude:: ../examples/get_tokens.py :linenos:
usage: call_intercept.py [-h] [--token TOKEN] user_email [{on,off}]positional arguments:user_email email address of user{on,off} operation to applyoptions:-h, --help show this help message and exit--token TOKEN admin access token to use
The script uses the access token passed via the CLI, reads one from the WEBEX_ACCESS_TOKEN environment variable or
obtains tokens via an OAuth flow. For the last option the integration parameters are read from environment variables which can be set in a .env
file
Source: call_intercept.py
.. literalinclude:: ../examples/call_intercept.py :linenos:
usage: queue_helper.py [-h] [--location LOCATION [LOCATION ...]][--queue QUEUE [QUEUE ...]][--join JOIN_AGENT [JOIN_AGENT ...]][--unjoin UNJOIN_AGENT [UNJOIN_AGENT ...]][--remove REMOVE_USER [REMOVE_USER ...]][--add ADD_USER [ADD_USER ...]] [--dryrun][--token TOKEN]Modify call queue settings from the CLIoptional arguments:-h, --help show this help message and exit--location LOCATION [LOCATION ...], -l LOCATION [LOCATION ...]name of location to work on. If missing then work onall locations.--queue QUEUE [QUEUE ...], -q QUEUE [QUEUE ...]name(s) of queue(s) to operate on. If missing thenwork on all queues in location.--join JOIN_AGENT [JOIN_AGENT ...], -j JOIN_AGENT [JOIN_AGENT ...]Join given user(s) on given queue(s). Can be "all" toact on all agents.--unjoin UNJOIN_AGENT [UNJOIN_AGENT ...], -u UNJOIN_AGENT [UNJOIN_AGENT ...]Unjoin given agent(s) from given queue(s). Can be"all" to act on all agents.--remove REMOVE_USER [REMOVE_USER ...], -r REMOVE_USER [REMOVE_USER ...]Remove given agent from given queue(s). Can be "all"to act on all agents.--add ADD_USER [ADD_USER ...], -a ADD_USER [ADD_USER ...]Add given users to given queue(s).--dryrun, -d Dry run; don't apply any changes--token TOKEN admin access token to use
The script uses the access token passed via the CLI, reads one from the WEBEX_ACCESS_TOKEN environment variable or
obtains tokens via an OAuth flow. For the last option the integration parameters are read from environment variables
which can be set in a queue_helper.env
file in the current directory.
Source: queue_helper.py
.. literalinclude:: ../examples/queue_helper.py :linenos:
The script uses service app credentials to get an access token and then use this access token to call Webex Calling APIs.
Source: service_app.py
.. literalinclude:: ../examples/service_app.py :linenos:
This script looks for unassigned TNs and assigns them to HGs that are forwarded to the locations main number. The idea is to catch all incoming calls to unassigned TNs and handle them accordingly.
usage: catch_tns.py [-h] [--test] [--location LOCATION] [--token TOKEN][--cleanup]optional arguments:-h, --help show this help message and exit--test test only; don't actually apply any config--location LOCATION Location to work on--token TOKEN admin access token to use.--cleanup remove all pooling HGs
Source: catch_tns.py
.. literalinclude:: ../examples/catch_tns.py :linenos: