Genesys Cloud - Main

 View Only

Discussion Thread View
  • 1.  Download data tables via API

    Posted 03-20-2025 14:19

    Hey everyone, 

    Not sure if I am going about this wrong, however I am attempting to automatically download data tables via API.  My python script is able to grab the final URLs to download, however I am needing a way to download them via python. I can utilize the webbrowser module in python, however I still need to authenticate.  Is there a Genesys API I can use to pass credentials or use the token to authenticate to be able to download these files?   Thanks in advance!


    #API/Integrations

    ------------------------------
    Chad Meyer
    Global Voice Engineer
    ------------------------------


  • 2.  RE: Download data tables via API
    Best Answer

    Posted 03-20-2025 15:45
    Edited by Jason Kleitz 03-20-2025 16:56

    Hi Chad,

    You can follow below steps to download Genesys Cloud datatables using the API.

    The process involves three main steps:

    1. Create an Export Job: Initiate an asynchronous export job for the datatable.
    2. Check Job Status: Monitor the status of the export job until it completes (either successfully or fails).
    3. Download the Exported File: If the job succeeds, download the exported CSV file using the provided download URL.This URL is provided as a property within the successful job response.

    API Endpoints

    We'll be using the following Genesys Cloud API endpoints:

    Prerequisites

    • Genesys Cloud User Account: You'll need a Genesys Cloud user account with the necessary permissions to access and export datatables. Specifically, you'll need a role that includes the architect:datatable:view and architect:datatable:export permissions.
    • API Token: You'll need an OAuth client with a token. The client should have the required permissions mentioned above. You can create an OAuth client in the Genesys Cloud Admin UI.

    Process Details (and where to find the download URI):

    1. Create Export Job:

      • You'll send a POST request to the /api/v2/flows/datatables/{datatableId}/export/jobs endpoint. The datatableId is a placeholder for the actual ID of the datatable you want to export.
      • Include your API token in the Authorization header of the request (e.g., Authorization: Bearer YOUR_TOKEN).
      • The API will respond with a JSON object containing information about the newly created export job, including a unique id for the job.
    2. Check Job Status:

      • Use the job id from the previous step.
      • Send GET requests to the /api/v2/flows/datatables/{datatableId}/export/jobs/{exportJobId} endpoint. Replace {datatableId} and {exportJobId} with the actual values.
      • Again, include your API token in the Authorization header.
      • The API response will be a JSON object containing the current status of the export job. The key property to monitor is status.
      • Keep checking the status periodically (e.g., every few seconds) until the status is either "Succeeded" or "Failed".
    3. Download the File (using the downloadURI property):

      • Crucially, when the job status is "Succeeded", the API response will include a property called downloadURI. This property contains the URL you need to use to download the exported CSV file.
      • Use an HTTP client (like the requests library in Python, or even your web browser) to make a GET request to the downloadURI. You must still include your API token in the Authorization header of this request as well.
      • The response to this GET request will be the actual CSV file data. You can then save this data to a file on your system.

    Example of a Successful Job Status Response (Illustrative):

    {
      "id": "your-export-job-id",
      "name": "ExportJob",
      "status": "Succeeded",
      "downloadURI": "https://api.mypurecloud.com/api/v2/downloads/some-unique-download-id?...",
      "dateCreated": "2023-10-27T10:00:00Z",
      "dateCompleted": "2023-10-27T10:01:00Z",
      "countRecordsProcessed": 12345
    }

    Key Considerations:

    • API Rate Limits: Be mindful of Genesys Cloud API rate limits. Introduce delays (e.g., using time.sleep() in Python) between status checks to avoid exceeding these limits.
    • Permissions: Double-check that your OAuth client and user account have the necessary permissions.
    • Region Specific URL: The examples use "https://api.mypurecloud.com". Remember to replace this with the correct API endpoint for your Genesys Cloud region.

    This comprehensive guide should enable you to successfully export and download your Genesys Cloud datatables using the API and Python. 



    ------------------------------
    Orhun Sahin
    Software Development Engineer
    ------------------------------



  • 3.  RE: Download data tables via API

    Posted 03-21-2025 09:56

    Ah, I didn't realize I could GET the url directly.  Thank you for the comprehensive guide!



    ------------------------------
    Chad Meyer
    Global Voice Engineer
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources