Rest API query through PowerShell / JSON to get incidents created within last "x" days

I'm wondering if anyone knows how I can limit down my current query to add qualifiers in my initial query to get Incidents that were created in the last "X" days.   

Right now I'm using the following via a PowerShell script (prefer to keep it in PowerShell for now)  to get all Incidents created and then dump the results into an Array.   Then I start filtering data that want with PowerShell commands I'm familiar with.   My goal is to make my initial query more targeted so that I don't have to download so much junk to later filter through and also cut down on execution time.  Left my temp troubleshooting items as comments etc as well for now. 

If there is documentation and a list of other types of search criteria i can use, such as who created etc. and someone can point me in the right direction for that as well it would be great. 

$JsonWebToken = "YOUR TOKEN HERE"

#Need to figure out how to add qalliviers to dynamically build the URI for the query.
#$UriBase = "https://api.samanage.com/"

$Headers = @{ "X-Samanage-Authorization" = "Bearer $JsonWebToken";

              "Accept"                   = "application/vnd.samanage.v2.1+json"

              "Content-Type"             = "application/json" }



$URI = "https://api.samanage.com/incidents.json?page="
$Page = 1

DO {
	
	$WebResults += Invoke-RestMethod -Uri ( $URI + $Page ) -Headers $Headers -Method Get -ResponseHeadersVariable ResponseHeaders
	$TotalResults = [int]( $ResponseHeaders.'X-Total-Count'[0] )
	$Page += 1
	Write-Host "Current Page = " $ResponseHeaders.'X-Current-Page'
	Write-Host "Result count = " $WebResults.count
	Write-Host " "

} UNTIL ($ResponseHeaders.'X-Current-Page' -eq $ResponseHeaders.'X-Total-Pages')



#$WebResults | Out-GridView
#$WebResults.Number
#$WebResults.Category.Name
#$WebResults.SubCategory.Name
#$WebResults.Assignee.Name
#$WebResults.Requester.Name
#$WebResults.Created_At
#$WebResults.Href



$Results = @()
ForEach($Ticket in $WebResults){

	$TempResults = [PSCustomObject]@{
		TicketNumber = $Ticket.Number
		Assignee = $Ticket.Assignee.Name
		Category = $Ticket.Category.Name
		SubCategory = $Ticket.SubCategory.Name
		Requester = $Ticket.Requester.Name
		DateCreated = $Ticket.Created_At
		Link = $Ticket.Href
	}
$Results += $TempResults
$Results.Count
}


$Results | Out-GridView

  • Hello! If you add the URL parameter "created[]=1" it will show you only incidents created in the last day.

    https://api.samanage.com/incidents.json?page=1&created[]=1

    This works for 1, 7, 14, 30, 60, 90 days and has the same restrictions as the filter in the Web UI.

    You can also search for a date range. I recommend creating the filter in the Web UI, and then looking at the URL after applying it. The API uses the same URL arguments for filtering: