
MHood176320 (Community Member) asked a question.
I am making an api call to download a detailed report from a specified build using powershell. This is done in a pipeline environment so I must use powershell and do not have access to httpie (Which works for me locally). I consistently get a 401 unauthorized error with the following code
$verb = "GET"
$hostName = "analysiscenter.veracode.com"
$path = "/api/5.0/detailedreport.do?build_id=27108280"
$timestamp = (Get-Date -UFormat %s).Split('.')[0]
$data = $verb + $timestamp + $path
# Compute the HMAC hash of the data
$hmacsha256 = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha256.Key = [Text.Encoding]::ASCII.GetBytes($veracodeAPISecret)
$signature = $hmacsha256.ComputeHash([Text.Encoding]::ASCII.GetBytes($data))
$signature = [Convert]::ToBase64String($signature)
# URL encode the results
Add-Type -AssemblyName System.Web
$authHeader = "VERACODE-HMAC-SHA256 id=$($veracodeAPIId), ts=$timestamp, sig=$([System.Web.HttpUtility]::UrlEncode($signature))"
# Define the headers for the request
$headers = @{
Authorization = $authHeader
}
# Make the request
$response = Invoke-WebRequest -Uri "https://$hostName$path" -Headers $headers -Method $verb
The ApiId and ApiKey are set correctly so I believe the issue is in setting the HMAC Header. Does anyone know what Im doing wrong or has anyone had success using Invoke-WebRequest to download the detailedReport
.png)
Good Morning MHood176320,
For these types of issues, we recommend opening a support case so this can be triaged and moved to the correct team. It looks like you will need assistance with the Integrations team. Once the the case is opened we will have a specialist contact you for further assistance.
Thanks,
Veracode Support