Delimited File Aggregation via API powershell

Hello,
i need to make an aggregation with a csv file via cc call api (in powershell)

i tried the api call (cc) using postman and it worked, so i took the equivalent script powershell from postman but i had the following error when using the Invoke-RestMethod (error 400)

Here is my script :

$token=Get-IdentityNowAuth

$baseUrl = "https://{{tenant}}.identitynow.com/cc/api/source/loadAccounts/{SourceID}"


$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($token.access_token)")

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")

# Add disableOptimization
$stringHeader.Name = "disableOptimization"
$stringContent = [System.Net.Http.StringContent]::new("true")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

# Add File
$multipartFile = $filePath
$FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "file"
$fileHeader.FileName = (filename)
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$multipartContent.Add($fileContent)

$body = $multipartContent


# Send the POST request
$response = Invoke-RestMethod -Uri $baseUrl -Method POST -Headers $headers -Body $body

Any Idea ?

1 Like

I was also having the same issue in PowerShell and ended up using Curl inside PowerShell.(Did not get a chance to dig deeper)

        $url =  "{tenant}/cc/api/source/loadAccounts/$SourceId"
        $FormHeader = 'Authorization: Bearer ' + <Token>
        $accountsFile = 'file=@"' + $FilePath+ '"'
        curl -v --location --request POST $url --header $FormHeader --form $accountsFile --ssl-no-revoke 

Please ensure the below are correct:

  1. If you are not already aware, Please ensure {SourceID} you get from cloudExternalId not the ID of the source.(find it in source.connectorAttributes.cloudExternalId)
  2. Ensure your tenant name contains “api” > “tenat.api.identitynow.com”
2 Likes

Hello @Sb_amir ,

Welcome to the Developer Community!

This can be accomplished in the latest version of the PowerShell SDK.

Installation and configuration details can be found at PowerShell SDK | SailPoint Developer Community.

Once installed and configured you can call the cmdlet.

If you want to aggregate accounts without passing the file:

Invoke-CCLoadAccounts -Id 32654 -DisableOptimization $true -WithHttpInfo

Passing a file

Invoke-CCLoadAccounts -Id 32654 -DisableOptimization $true -File /Users/tyler.mairose/Accounts.csv -WithHttpInfo

Including the WithHttpInfo switch will return the whole response object with status code etc, excluding will just return the results of the request.

3 Likes

Hello guys !

Thank you for your answers, i appreciate the reactivity!

I tried the SDK command and it worked for me, so problem resolved :smile:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.