sassoftware / ci360-download-client-python

ci360 data download client program using Python
Apache License 2.0
14 stars 11 forks source link

SAS Customer Intelligence 360 Download Client: Python

Overview

This Python script enables you to download cloud-hosted data tables from SAS Customer Intelligence 360.

The script can perform the following tasks:

This topic contains the following sections:

Configuration

  1. Install Python (version 3 or later) from https://www.python.org/.

    Tip: Select the option to add Python to your PATH variable. If you choose the advanced installation option, make sure to install the pip utility.

  2. Make sure the following modules are installed for Python: argparse, backoff, base64, codecs, csv, gzip, json, os, pandas, PyJWT, requests, sys, time, and tqdm.

    In most cases, many of the modules are installed by default. To list all packages that are installed with Python (through pip or by default), use this command:
    python -c help('modules')

    Tip: In most situations, you can install the non-default packages with this command:
    pip install backoff pandas PyJWT requests tqdm

  3. Create an access point in SAS Customer Intelligence 360.

    1. From the user interface, navigate to General Settings > External Access > Access Points.
    2. Create a new access point if one does not exist.
    3. Get the following information from the access point:
      External gateway address: e.g. https://extapigwservice-<server>/marketingGateway  
      Name: ci360_agent  
      Tenant ID: abc123-ci360-tenant-id-xyz  
      Client secret: ABC123ci360clientSecretXYZ  
  4. Download the Python script from this repository and save it to your local machine.

  5. In the ./dsccnfg/config.txt file, set the following variables for your tenant:

     agentName = ci360_agent
     tenantId  = abc123-ci360-tenant-id-xyz
     secret    = ABC123ci360clientSecretXYZ
     baseUrl   = https://extapigwservice-<server>/marketingGateway/discoverService/dataDownload/eventData/
  6. Verify the installation by running the following command from command prompt:
    py discover.py –h

Using the Download Script

Considerations

Before starting a download, make a note of the following things:

Running the Script

  1. Open a command prompt.
  2. Run the discover.py script with parameter values that are based on the tables that you want to download. For example, to download the detail tables with a start and end date range, you can run the following command:
    py discover.py -m detail -st 2019-12-01T00 -et 2019-12-01T12

Note: On Unix-like environments and Macs, the default py or python command might default to Python 2 if that version is installed. Uninstall earlier versions of Python, or explicitly call Python 3 when you run script like this example:

python3 discover.py -m detail -st 2019-12-01T00 -et 2019-12-01T12

You can verify which version runs by default with the following command: python --version


These are the parameters to use when you run the discover.py script:

Parameter Description
-h Displays the help
-m The table set to download. Use one of these values:
  • detail (This value downloads Detail mart tables and the partitioned CDM tables - cdm_contact_history and cdm_response_history.)
  • dbtReport
  • snapshot (for CDM tables that are not partitioned, identity tables, and metadata tables)
-svn Specify a specific schema of tables to download.
-st The start value in this datetime format: yyyy-mm-ddThh
-et The end value in this datetime format: yyyy-mm-ddThh
-ct The category of tables to download. When the parameter is not specified, you download tables for all the categories that you have a license to access.

To download tables from a specific category, you can use one of these values:
  • cdm
  • discover
  • engagedigital
  • engagedirect
  • engagemetadata
  • engagemobile
  • engageweb
  • engageemail
  • optoutdata
  • plan

For more information, see Schemas and Categories.
-d Download only the changes (the delta) from the previous download. Set the value to yes or no.
-l For partitioned tables, specify a limit of partitions to download. For example, -l 150 downloads only the first 150 partitions of a specific set.
-a Append the download to the existing files. Set the value to yes or no.
-cf Create a CSV file from the download tables. Set the value to yes or no.
-cd Specify a delimiter other than the default
-ch Include a column header in the first row. Set the value to yes or no.
-cl Clean the download .zip files. By default, the files are deleted, but you can set this parameter to no to keep them.

Note: The start and end ranges are only used for the script's first run. After the first run, the download history is stored in the dsccnfg directory. To force the script to use the variables for start date and end date, delete or move the history information.

In addition, the values in the dataRangeStartTimeStamp column and dataRangeEndTimeStamp column in the download history tables are in the UTC time zone. The values in the download_dttm column are in the local time zone.

Examples

Contributing

We welcome your contributions! Please read CONTRIBUTING.md for details on how to submit contributions to this project.

License

This project is licensed under the Apache 2.0 License.

Additional Resources

For more information, see Downloading Data Tables with the REST API in the Help Center for SAS Customer Intelligence 360.