Hi, Can someone please suggest me solution for one issue I am facing while trying to use Sailpoint API from Powershell. Here is the detailed info about issue:
This is one simple script I have:
$Parameters = @{
"Filters" = 'name co "Test User"'
}
# Accounts List
try {
Invoke-Paginate -Function "Get-Accounts" -Increment 250 -Limit 1000 -InitialOffset 0 -Parameters $Parameters
} catch {
Write-Host ("Exception occurred when calling Invoke-Paginate: {0}" -f $_.ErrorDetails)
Write-Host ("Response headers: {0}" -f $_.Exception.Response.Headers)
}
I am executing it from Powershell version 7 but its giving error message:
PS C:\Users\Documents\Sailpoint powershell works\SPAPITest> .\Test-api-2.ps1
Conversion from JSON failed with error: Unexpected character encountered while parsing value: A. Path '', line 0, position 0.
Trial with other script: I have one more script:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Bearer <token>")
$certData = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2(, [Convert]::FromBase64String($cert))
$response = Invoke-RestMethod 'https://tenant.api.identitynow.com/v3/certifications' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
while running this script I get error message:
PS C:\Users\Documents\Sailpoint powershell works\SPAPITest> .\test2.ps1
Invoke-RestMethod: C:\Users\Documents\Sailpoint powershell works\SPAPITest\test2.ps1:8
Line |
8 | $response = Invoke-RestMethod 'https://tenant.api.identitynow.com/v3/ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| A connection attempt failed because the connected party did not properly respond after a period of time, or
| established connection failed because connected host has failed to respond.
Trial case 3: for the same script I did little modification and tried to run from Powershell version 5.2:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Bearer <token>")
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$response = Invoke-RestMethod 'https://tenant.api.identitynow.com/v3/certifications' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
It works fine.
But when I modify above script for powershell 7 version like:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Bearer <token>")
$certData = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2(, [Convert]::FromBase64String($cert))
$response = Invoke-RestMethod 'https://tenant.api.identitynow.com/v3/certifications' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
it gives error message:
Invoke-RestMethod: C:\Users\Documents\Sailpoint powershell works\SPAPITest\test2.ps1:8
Line |
8 | $response = Invoke-RestMethod 'https://tenant.api.identitynow.com/v3/ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| A connection attempt failed because the connected party did not properly respond after a period of time, or
| established connection failed because connected host has failed to respond.
null
Could you please suggest if anything I am missing or changes I need to make to fix this issue.