Issues with exact same API call in Powershell that has no issues in Postman

I’m using a search API that is working fine in Postman but does not return any results when I run it with Powershell.

I’m having PowerShell print the body variable I’m passing into the Invoke-RestMethod so I know it’s not Powershell formatting something differently.

Here’s the body variable that PowerShell wrote out that is identical to the body used by Postman.

{
            
  "query": {
            
    "query": "recipient.name:* AND action:\"Password Change\" AND created:>=2023-01-02T09\\:27\\:26.000Z"
            
  },
            
  "indices": [
            
    "accountactivities"
            
  ],
            
  "queryType": "SAILPOINT",
            
  "queryVersion": "5.2",
            
  "fields": [
            
    "name"
            
  ],
            

            
  "timeZone": "America/Chicago"
            

            
  
            
}

The headers:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer INSERT_TOKEN_HERE")
$headers.Add("Content-Type", "text/plain")

And the URI:
https://INSERT_ORG_NAME.api.identitynow.com/v3/search?limit=1000

And while this returns plenty of results in Postman it never returns anything in Powershell. I’m completely stumped, does anyone have any ideas?

If the quotes etc are formatted/escaped correctly the issue may be with your header → Content type

It should be set to “application/json”

2 Likes

That was it, thank you!!!