Performing what should be a simple DQL query via API, I get a 401 - Could not parse JWT". I understand this to be an token issue.
The confusion is that the token is fully usable in a different api call. (I intentionally over-provisioned the token giving ALL 38 scopes)
The failing query works in the swagger test -- unless I explicitly provide a token instead of my login.
I do recognize there is a difference (which I don’t still fully understand) in the “live” vs “apps” url, SHould I be using a different form of token? If so, can I get guided to it? THank you in advance.
THIS CODE WORKS:
$ApiToken = "dt0c01.REDACTED"
$Uri = "https://{environmentid}.apps.dynatrace.com/platform/storage/query/v1/query:execute?enrich=metric-metadata"
$Body = @"
{
"defaultSamplingRatio": 1,
"defaultScanLimitGbytes": 10,
"defaultTimeframeEnd": "2026-04-08T00:00:00.000Z",
... TRIMMED, not directly relevant ....
}
"@
$DQLQuery = Invoke-RestMethod -Uri $MetaUrl -Headers $Headers -Method POST -Body $Body
$DQLQuery | ConvertTo-Json -Depth 99 | Out-File -FilePath "C:\temp\DQLQuery.json" -Encoding UTF8
Write-Host "DQLQuery response saved to C:\temp\DQLQuery.json"