PureCloud Platform API SDK

254.0.0 · active · verified Sun Mar 29

The `PureCloudPlatformClientV2` library is the official Python SDK for interacting with the Genesys Cloud Platform API. It provides a comprehensive set of classes and methods generated from the API's Swagger definition, allowing developers to programmatically manage various aspects of their Genesys Cloud environment. The library is actively maintained by Genesys Developer Evangelists, with releases tied to the Genesys Cloud API's update cadence, typically following Semantic Versioning to reflect changes in the underlying API. The current version is 254.0.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate using the Client Credentials Grant and fetch the current user's details. Ensure your `GENESYS_CLOUD_CLIENT_ID`, `GENESYS_CLOUD_CLIENT_SECRET`, and optionally `GENESYS_CLOUD_REGION` are set as environment variables. This grant type is suitable for non-human applications or services.

import PureCloudPlatformClientV2
import os

# Configure API client with Client Credentials Grant
# Ensure GENESYS_CLOUD_CLIENT_ID and GENESYS_CLOUD_CLIENT_SECRET are set as environment variables
CLIENT_ID = os.environ.get('GENESYS_CLOUD_CLIENT_ID', '')
CLIENT_SECRET = os.environ.get('GENESYS_CLOUD_CLIENT_SECRET', '')
GENESYS_CLOUD_REGION = os.environ.get('GENESYS_CLOUD_REGION', 'mypurecloud.com') # e.g., mypurecloud.ie

# Set the Genesys Cloud region (e.g., 'mypurecloud.ie', 'mypurecloud.com.au')
# Default is mypurecloud.com
PureCloudPlatformClientV2.configuration.host = f'https://api.{GENESYS_CLOUD_REGION}'

api_client = PureCloudPlatformClientV2.api_client.ApiClient()

try:
    # Authenticate using client credentials
    api_client.get_client_credentials_token(CLIENT_ID, CLIENT_SECRET)
    print("Authentication successful!")

    # Instantiate an API class (e.g., UsersApi)
    users_api = PureCloudPlatformClientV2.UsersApi(api_client)

    # Make an API call (e.g., get the authenticated user's information)
    me = users_api.get_users_me()
    print(f"Authenticated user: {me.name} (ID: {me.id})")

except PureCloudPlatformClientV2.rest.ApiException as e:
    print(f"Exception when calling Genesys Cloud API: {e}")
    print(f"Ensure GENESYS_CLOUD_CLIENT_ID and GENESYS_CLOUD_CLIENT_SECRET are set correctly and have the necessary permissions.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →