functions/Initialize-XMLReport.ps1

<#
.SYNOPSIS
Generates an XML Report for a given Project.
  
.DESCRIPTION
Used to generates XML reports for a given project. This returns the JOB ID needed to retrieve the report.
  
.EXAMPLE
Initialize-XMLReport "My project"
  
#>


Function Initialize-XMLReport
{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$ProjectName
    )
    
    #/api/projects/{project-id}/report/{report-type}
    $ProjectID = Get-ProjectID $ProjectName
    $ProjectID = $ProjectID[0]
    $uri = $CDXSERVER + "/api/projects/" + $ProjectID + "/report/xml"
        
    # Defines the Triage status for the filter that will be pulled from Code Dx for the report.
    # Currently pulling all data that is not:
    # False, Positive, Mitigated, ignored, Fixed, or Gone.
    $statusArray = (7,5,9,4,3)
     
    #Defines whether or not to ignore archived findings from Code Dx, effectively excluding them from the report.
    $globalconfig = [pscustomobject]@{
        'ignoreArchived' = $true
    }
    
    #Defines the filter information for the JSON payload
    $filter = [pscustomobject]@{
        '~status' = $statusArray
        'globalConfig' = $globalconfig
    }
    
    #Defines the report configuration information for the JSON payload
    $config = [pscustomobject]@{
        'includeStandards' = $true
        'includeSource' = $true
        'includeRuleDescriptions' = $true
    }
    
    $body = ConvertTo-Json @{
        "filter" = $filter
        "config" = $config
    }
    
    Write-Verbose ( $body | Format-Table | Out-String )

    $GenerateXMLReport = Invoke-RestMethod -Uri $uri -Method Post -Body $body -Headers $headers -ContentType "application/json" 
    Write-Verbose ( $GenerateXMLReport | Format-Table | Out-String )
    Return $GenerateXMLReport
}