# 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="/files/SjDZg1vVPjwLk6hb8hK8" alt=""></td><td>string</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>The domain for your SeaLights account lab.</td></tr><tr><td>SL_API_TOKEN</td><td><img src="/files/SjDZg1vVPjwLk6hb8hK8" alt=""></td><td>string</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/JPN6guiaj1m2NCuEjLrN" 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="/files/SjDZg1vVPjwLk6hb8hK8" alt=""></td><td>string</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>App to report</td></tr><tr><td>BRANCH_NAME</td><td><img src="/files/SjDZg1vVPjwLk6hb8hK8" alt=""></td><td>string</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>Branch to report</td></tr><tr><td>ALL_BUILDS</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>number ms</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>number ms</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/0MOEn4Y7w4YrGgw4UKBn" 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="/files/SjDZg1vVPjwLk6hb8hK8" alt=""></td><td>AppBranch[]</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>List of App-Branches for the report.</td></tr><tr><td>INTERVAL</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>number ms</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" alt=""></td><td>number ms</td><td><img src="/files/nvUrSemcIPwkTGA6mvZL" 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="/files/nvUrSemcIPwkTGA6mvZL" 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/integrations/sample-integrations/generating-a-trend-report-quality-analytics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
