The Logs API requires the format for date query params to be ISO8601 (i.e. 2024-10-21T16:24:13Z or Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%SZ'). The existing Get-OktaLogs cmdlet doesn't preserve formats, causing the API call to fail.
There are several routes we can explore to fix the issue:
- Update the Cmdlet interface to receive strings instead of dates:
$until = $dateTo.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$since = $dateFrom.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
Get-OktaLogs -since $since -until $until
- Keep the same Cmdlet interface but address the format internally
Get-OktaLogs -since $sinceUtcDate -until $untilUtcDate
//OktaSystemLogApi.ps1
// Assume $Since is already in UTC format
if ($Since) {
$LocalVarQueryParameters['since'] = $Since.ToString("yyyy-MM-ddTHH:mm:ssZ")
}
We should update docs to show examples of how to use the logs cmdlets