# Generating a Trend Report (Quality Analytics)

Using Quality Analytics API, you can generate a report that shows coverage over time.\
If you need to generate a trend report, you can reuse the following sample code to generate a report and get the URL to view it.

**Please checkout SeaLights API Reference to see the full and latest API syntax available.**

### Script Dependencies <a href="#script-dependencies" id="script-dependencies"></a>

* jq
* curl

### Script Configuration <a href="#script-configuration" id="script-configuration"></a>

<table><thead><tr><th width="154.01953125">Variable</th><th width="87.1484375">Required</th><th width="81.4765625">Type</th><th width="71.4609375">Default</th><th>Description</th></tr></thead><tbody><tr><td>DOMAIN</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FHiqKxVnDoOLH0P6P0jAt%2Fcheck_circle.svg?alt=media&#x26;token=15d4ebba-b19c-43c5-9e5b-17b0cc36d41d" alt=""></td><td>string</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>The domain for your SeaLights account lab.</td></tr><tr><td>SL_API_TOKEN</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FHiqKxVnDoOLH0P6P0jAt%2Fcheck_circle.svg?alt=media&#x26;token=15d4ebba-b19c-43c5-9e5b-17b0cc36d41d" alt=""></td><td>string</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>An API token for your lab (generated in the settings tab of the web app)</td></tr></tbody></table>

### Script Output <a href="#script-output" id="script-output"></a>

* The output of the script is written to: `report.url`

{% code overflow="wrap" lineNumbers="true" %}

```
https://<DOMAIN>/quality-analytics/trend-report/single/<REPORT_ID>;from_public_api=true
```

{% endcode %}

## Generating a Coverage Trend Report <a href="#generating-a-coverage-trend-report" id="generating-a-coverage-trend-report"></a>

Coverage Trend report allows the user to select test stages from a single application and see aggregated data over time or over reference builds.

This report will show:

* Selected test stages overall and modified coverage (aggregated, and broken down per test stage)
* Entire build coverage and modified coverage (aggregated across all test stages, optional additional chart element)
* Number of methods and modified methods (optional additional chart element)

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FM4mFcGRZaxhmCjNsUvkl%2FScreen%20Shot%202022-02-07%20at%200.11.48%20(2).png?alt=media&#x26;token=8ac0ba3f-c58f-4aac-b523-97f17431d4cb" alt=""><figcaption></figcaption></figure>

More information about the Coverage Trend report can be found [here](https://docs.sealights.io/knowledgebase/coverage-trend-report).

### Report Configuration <a href="#report-configuration" id="report-configuration"></a>

<table><thead><tr><th width="161.4140625">Variable</th><th width="87.20703125">Required</th><th width="179.2421875">Type</th><th width="135.984375">Default</th><th>Description</th></tr></thead><tbody><tr><td>APP_NAME</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FHiqKxVnDoOLH0P6P0jAt%2Fcheck_circle.svg?alt=media&#x26;token=15d4ebba-b19c-43c5-9e5b-17b0cc36d41d" alt=""></td><td>string</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>App to report</td></tr><tr><td>BRANCH_NAME</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FHiqKxVnDoOLH0P6P0jAt%2Fcheck_circle.svg?alt=media&#x26;token=15d4ebba-b19c-43c5-9e5b-17b0cc36d41d" alt=""></td><td>string</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>Branch to report</td></tr><tr><td>ALL_BUILDS</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>boolean</td><td>true</td><td>When true, show trend over time.<br>When false, show trend over reference builds.</td></tr><tr><td>INTERVAL</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>ONE_WEEK |<br>TWO_WEEKS |<br>THREE_WEEKS |<br>FOUR_WEEKS |<br>ONE_MONTH</td><td>ONE_MONTH</td><td>When ALL_BUILDS is true, defines at which intervals to calculate coverage.</td></tr><tr><td>SELECTED_TEST_STAGES</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>string[]</td><td>8 most active test stages</td><td>Defines which test stages should be included in the report.</td></tr><tr><td>DATE_RANGE_LABEL</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>LAST_MONTH |<br>LAST_TWO_MONTHS |<br>LAST_THREE_MONTHS |<br>LAST_SIX_MONTHS |<br>LAST_YEAR |<br>CUSTOM</td><td>LAST_SIX_MONTHS</td><td>Defines the date range of the report</td></tr><tr><td>REPORT_START_DATE</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>number ms</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>When date range is CUSTOM, defines the start date of the report.</td></tr><tr><td>REPORT_END_DATE</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>number ms</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>When date range is CUSTOM, defines the end date of the report.</td></tr><tr><td>NUM_OF_METHODS_CHART_ELEMENT</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>boolean</td><td>false</td><td>the report will include an additional chart element representing the number of methods.</td></tr><tr><td>ALL_TEST_STAGES</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>boolean</td><td>false</td><td>the report will include an additional chart line representing all test stages coverage.</td></tr><tr><td>COVERAGE_GATE_CHART_ELEMENT</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>boolean</td><td>false</td><td>Additional chart line representing the coverage gate.</td></tr></tbody></table>

### Script <a href="#script" id="script"></a>

{% code overflow="wrap" lineNumbers="true" %}

```bash
#!/usr/bin/env bash
DOMAIN="<domain>"
SL_API_TOKEN="<api-token>"

# Edit these variables to set the desired report configuration
APP_NAME="app1"
BRANCH_NAME="branch1"
#SELECTED_TEST_STAGES=("Unit Tests" "E2E Tests")
#DATE_RANGE_LABEL="LAST_SIX_MONTHS"
#REPORT_START_DATE="2022-01-22"
#REPORT_END_DATE="2022-02-22"
#ALL_BUILDS="true"
#INTERVAL="ONE_MONTH"
#NUM_OF_METHODS_CHART_ELEMENT="false"
#ALL_TEST_STAGES="false"
#COVERAGE_GATE_CHART_ELEMENT="false"

echo "Creating request payload"

if [ -z ${APP_NAME+x} ]; then
    echo "Missing app name"
    exit 1
fi
if [ -z ${BRANCH_NAME+x} ]; then
    echo "Missing branch name"
    exit 1
fi

REQUEST_PAYLOAD=$(
    jq -n \
        --arg appName "$APP_NAME" \
        --arg branchName "$BRANCH_NAME" \
        '{appName: $appName, branchName: $branchName}'
)

if [ ! -z ${ALL_BUILDS+x} ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg allBuilds "$ALL_BUILDS" \
            '.allBuilds |= $allBuilds'
    )
fi

if [ "$ALL_BUILDS" == "true" -a ! -z "${INTERVAL+x}" ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg interval "$INTERVAL" \
            '.interval |= $interval'
    )
fi

if [ ! -z "${SELECTED_TEST_STAGES+x}" ]; then
    TEST_STAGES_ARR=$(for i in "${SELECTED_TEST_STAGES[@]}"; do echo "\"$i\""; done)
    TEST_STAGES_JSON_ARR="[$(sed 's/" "/", "/g' <<< "$(echo $TEST_STAGES_ARR)")]"

    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --argjson testStages "$TEST_STAGES_JSON_ARR" \
            '.testStages |= $testStages'
    )
fi

if [ ! -z "${DATE_RANGE_LABEL+x}" ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg dateRangeLabel "$DATE_RANGE_LABEL" \
            '.dateRangeLabel |= $dateRangeLabel'
    )
fi

if [ "$DATE_RANGE_LABEL" == "CUSTOM" ]; then
    if [ -z ${REPORT_START_DATE+x} ]; then
        echo "Missing start date"
        exit 1
    fi
    if [ -z ${REPORT_END_DATE+x} ]; then
        echo "Missing end date"
        exit 1
    fi

    REPORT_START_DATE_UNIX=`date -d "${REPORT_START_DATE}"  +%s%3N`
    REPORT_END_DATE_UNIX=`date -d "${REPORT_END_DATE}"  +%s%3N`
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --argjson from $REPORT_START_DATE_UNIX \
            --argjson to $REPORT_END_DATE_UNIX \
            '.from |= $from | .to |= $to'
    )
fi

if [ ! -z ${DATE_RANGE_LABEL+x} ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg dateRangeLabel "$DATE_RANGE_LABEL" \
            '.dateRangeLabel |= $dateRangeLabel'
    )
fi

if [ ! -z ${NUM_OF_METHODS_CHART_ELEMENT+x} ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg numOfMethodsChartElement "$NUM_OF_METHODS_CHART_ELEMENT" \
            '.numOfMethodsChartElement |= $numOfMethodsChartElement'
    )
fi

if [ ! -z ${ALL_TEST_STAGES+x} ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg allTestStages "$ALL_TEST_STAGES" \
            '.allTestStages |= $allTestStages'
    )
fi

if [ ! -z ${COVERAGE_GATE_CHART_ELEMENT+x} ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg coverageGateChartElement "$COVERAGE_GATE_CHART_ELEMENT" \
            '.coverageGateChartElement |= $coverageGateChartElement'
    )
fi

echo "Getting report url: ${REQUEST_PAYLOAD}"

RESPONSE=$(curl -s -X POST -H "Authorization: Bearer $SL_API_TOKEN" \
            -H "Accept: application/json" -H "Content-Type: application/json" --data "${REQUEST_PAYLOAD}" \
            "https://$DOMAIN/sl-api/v1/quality-analytics/trend-reports/single/url"
)
ERROR_MSG=$(
    echo $RESPONSE | jq -r '.error.message'
)
ERROR_CODE=$(
    echo $RESPONSE | jq -r '.error.code'
)
REPORT_URL=$(
    echo $RESPONSE | jq -r '.data.reportUrl'
)

if [ "${ERROR_CODE}" != "null" ]; then
    echo $ERROR_MSG
    exit $ERROR_CODE
fi

echo "Saving url '$REPORT_URL' to './report.url'"
echo $REPORT_URL > 'report.url'
```

{% endcode %}

## Generating a Group Coverage Trend Report

Group Coverage Trend report allows the user to select multiple applications and see aggregated data over time.

This report will show:

* All applications aggregated overall coverage and modified coverage
* Per application overall coverage and modified coverage
* Number of methods and modified methods (optional additional chart element)

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FmOi9J3IKppbrnWU7rIQT%2FScreen%20Shot%202022-03-10%20at%2016.16.35.png?alt=media&#x26;token=988f5a51-7efa-4ae9-b0c6-c41f77436c21" alt=""><figcaption></figcaption></figure>

More information about the Group Coverage Trend report can be found here.

### Report Configuration <a href="#report-configuration.1" id="report-configuration.1"></a>

<table data-header-hidden><thead><tr><th width="162.4296875">Variable</th><th width="103.8203125">Required</th><th>Type</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>APP_BRANCHES</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FHiqKxVnDoOLH0P6P0jAt%2Fcheck_circle.svg?alt=media&#x26;token=15d4ebba-b19c-43c5-9e5b-17b0cc36d41d" alt=""></td><td>AppBranch[]</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>List of App-Branches for the report.</td></tr><tr><td>INTERVAL</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>ONE_WEEK |<br>TWO_WEEKS |<br>THREE_WEEKS |<br>FOUR_WEEKS |<br>ONE_MONTH</td><td>ONE_MONTH</td><td>Defines at what intervals to calculate coverage.</td></tr><tr><td>DATE_RANGE_LABEL</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>LAST_MONTH |<br>LAST_TWO_MONTHS |<br>LAST_THREE_MONTHS |<br>LAST_SIX_MONTHS |<br>LAST_YEAR |<br>CUSTOM</td><td>LAST_SIX_MONTHS</td><td>Defines the date range of the report.</td></tr><tr><td>REPORT_START_DATE</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>number ms</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>When date range is CUSTOM, defines the start date of the report.</td></tr><tr><td>REPORT_END_DATE</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>number ms</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>When date range is CUSTOM, defines the end date of the report.</td></tr><tr><td>NUM_OF_METHODS_CHART_ELEMENT</td><td><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fs1SOT5enrcGSGrgJVWOF%2Fclose.svg?alt=media&#x26;token=d416d4cb-ffa9-4a4a-bcbf-24d94174c3d4" alt=""></td><td>boolean</td><td>false</td><td>the report will include an additional chart element representing the number of methods.</td></tr></tbody></table>

### Script <a href="#script.1" id="script.1"></a>

{% code overflow="wrap" lineNumbers="true" %}

```bash
#!/usr/bin/env bash
DOMAIN="<domain>"
SL_API_TOKEN="<api-token>"

# Edit these variables to set the desired report configuration
APP_BRANCHES='[{"appName": "app1", "branchName": "branch1"}]'
#DATE_RANGE_LABEL="LAST_SIX_MONTHS"
#REPORT_START_DATE="2022-01-22"
#REPORT_END_DATE="2022-02-22"
#INTERVAL="ONE_MONTH"
#NUM_OF_METHODS_CHART_ELEMENT="false"

echo "Creating request payload"

if [ -z ${APP_BRANCHES+x} ]; then
    echo "Missing app-branch list"
    exit 1
fi

REQUEST_PAYLOAD=$(
    jq -n \
        --argjson appBranches "$APP_BRANCHES" \
        '{appBranches: $appBranches}'
)

if [ ! -z "${INTERVAL+x}" ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg interval "$INTERVAL" \
            '.interval |= $interval'
    )
fi

if [ ! -z "${DATE_RANGE_LABEL+x}" ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg dateRangeLabel "$DATE_RANGE_LABEL" \
            '.dateRangeLabel |= $dateRangeLabel'
    )
fi

if [ "$DATE_RANGE_LABEL" == "CUSTOM" ]; then
    if [ -z ${REPORT_START_DATE+x} ]; then
        echo "Missing start date"
        exit 1
    fi
    if [ -z ${REPORT_END_DATE+x} ]; then
        echo "Missing end date"
        exit 1
    fi

    REPORT_START_DATE_UNIX=`date -d "${REPORT_START_DATE}"  +%s%3N`
    REPORT_END_DATE_UNIX=`date -d "${REPORT_END_DATE}"  +%s%3N`
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --argjson from $REPORT_START_DATE_UNIX \
            --argjson to $REPORT_END_DATE_UNIX \
            '.from |= $from | .to |= $to'
    )
fi

if [ ! -z ${DATE_RANGE_LABEL+x} ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg dateRangeLabel "$DATE_RANGE_LABEL" \
            '.dateRangeLabel |= $dateRangeLabel'
    )
fi

if [ ! -z ${NUM_OF_METHODS_CHART_ELEMENT+x} ]; then
    REQUEST_PAYLOAD=$(
        echo $REQUEST_PAYLOAD | jq \
            --arg numOfMethodsChartElement "$NUM_OF_METHODS_CHART_ELEMENT" \
            '.numOfMethodsChartElement |= $numOfMethodsChartElement'
    )
fi

echo "Getting report url: ${REQUEST_PAYLOAD}"

RESPONSE=$(curl -s -X POST -H "Authorization: Bearer $SL_API_TOKEN" \
            -H "Accept: application/json" -H "Content-Type: application/json" --data "${REQUEST_PAYLOAD}" \
            "https://$DOMAIN/sl-api/v1/quality-analytics/trend-reports/group/url"
)
ERROR_MSG=$(
    echo $RESPONSE | jq -r '.error.message'
)
ERROR_CODE=$(
    echo $RESPONSE | jq -r '.error.code'
)
REPORT_URL=$(
    echo $RESPONSE | jq -r '.data.reportUrl'
)

if [ "${ERROR_CODE}" != "null" ]; then
    echo $ERROR_MSG
    exit $ERROR_CODE
fi

echo "Saving url '$REPORT_URL' to './report.url'"
echo $REPORT_URL > 'report.url'
```

{% endcode %}

&#x20;
