# CTI_DownloadReport()

This subprocedure is used to download a report from the CyberSource REST reporting APIs. This subprocedure requires a record for your merchant ID in CTICFGRPT, and you must populate the record with a shared and secret key pair for use with CyberSource's HTTP Signature Authentication. For more information on generating these keys, please see this guide from CyberSource: [Create a Shared Secret Key for HTTP Signature Authentication](https://developer.cybersource.com/api/developer-guides/dita-gettingstarted/authentication/createSharedKey.html)

The [ADDRPTKEY](https://isupport.katointegrations.com/cti/addrptkey.md) command can be used to easily create a record for your merchant ID and generated security keys in CTICFGRPT.

The report will be downloaded to an IFS file in the download directory specified in your CTICFGMCH record. For the CTI_REPORT_BATCHDETAIL and CTI_REPORT_EXCEPTIONDETAIL reports, this file can be parsed with the corresponding parsing subprocedure. If you are downloading a custom report, please reach out to our support team at <a href="mailto:isupport@katointegrations.com">isupport@katointegrations.com</a> for guidance on parsing the downloaded report.

If an error occurs, this subprocedure will return *OFF, and information about the error will be present in the pErrorDS parameter which contains a CTI_ErrorDS_t data structure.

## Subprocedure Prototype

```rpgle
      // Returns *OFF if an error occurs during processing, *ON otherwise.
     D CTI_DownloadReport...
     D                 PR              N   Extproc('CTI_DownloadReport')

      // Unique ID generated with CTI_NextUniqueID()
      // Required
     D  pUniqueId                          Const Like(CTI_UniqueId_t)

      // A data structure containing configuration information for the report to
      //   be downloaded
      // Required
     D  pDownloadReportDS...
     D                                     LikeDS(CTI_DownloadReportDS_t)

      // Error data structure used to capture subprocedure and CyberSource errors
      // Required
     D  pErrorDS                           LikeDS(CTI_ErrorDS_t)
```


## Data Structures

### CTI_DownloadReportDS_t

```rpgle
     D CTI_DownloadReportDS_t...
     D                 DS                  Qualified Template Inz

      // Merchant ID used to process the transaction
      // Required
     D  MerchantId                         Like(CTI_MerchantId_t)

      // CyberSource environment where the report will be retrieved from
      // Required
      // Valid values: CTI_ENV_PROD, CTI_ENV_TEST
     D  Environment                   5A

      // Unique label to identify the security key in CTICFGRPT to be used
      // Default: CTI_DEFAULT
     D  KeyLabel                     50A   Varying Inz(CTI_DEFAULT)

      // Organization under which the report was generated in the CyberSource
      //   business center
     D  OrganizationId...
     D                                     Like(CTI_MerchantId_t)

      // Name of the report to be downloaded. This can be one of the pre-defined
      //   constants, or any custom report name
      // Valid values: CTI_REPORT_BATCHDETAIL, CTI_REPORT_EXCEPTIONDETAIL, text
     D  ReportName                         Like(CTI_ReportName_t)

      // End date for the report
     D  ReportDate                     D

      // Name of the file where the report will be downloaded. This file will be
      //   saved in the default download directory set for the specified merchant
      //   ID in CTICFGMCH
     D  Filepath                           Like(CTI_FilePath_t)
```


### CTI_ErrorDS_t

```rpgle
     D CTI_ErrorDS_t   DS                  Qualified Template Inz

      // Name of subprocedure returning error
     D  Subproc                     132A   Varying

      // Message ID of error message
     D  MessageId                     7A

      // Error message text
     D  Message                    1024A   Varying

      // Error message source
     D  Source                       10A

      // IFS filepath of generated log file
     D  LogFile                            Like(CTI_FilePath_t)
```


## Input Table Files

### CTICFGRPT

| Field Name | Long Field Name | Data Type | Field Title | Comments |
|---|---|---|---|---|
| `MERCHANTID` | `MERCHANTID` | `VARCHAR(30)` | Merchant ID |  |
| `ENV` | `ENVIRONMENT` | `VARCHAR(5)` | CyberSource Environment |  |
| `KEYLABEL` | `KEYLABEL` | `VARCHAR(50)` | Key Label |  |
| `SHAREDKEY` | `SHAREDKEY` | `VARCHAR(36)` | Shared Key |  |
| `SECRETKEY` | `SECRETKEY` | `VARCHAR(50)` | Secret Key |  |

