How do I update Platform in account via RestAPI with Powershell?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I update Platform in account via RestAPI with Powershell?

L1 Bithead

I need to update the platform of an account via RestAPI. The new platform does belong to a different device type than the old platform.

 

I'm trying this in powershell but I keep getting an error 400.

 

"function Set-PlatformId {

  param(

    [Parameter(Mandatory)]

    [string]$AccountId,

 

    [Parameter(Mandatory)]

    [string]$PlatformId

  )

 

  $accountIdTrim = $AccountId.Trim()

  $platformIdTrim = $PlatformId.Trim()

  $apiUrl = "$PCloudURL/API/Accounts/$accountIdTrim"

 

  $body = @(

    @{

      op  = "replace"

      path = "/platformID"

      value = "NewPlatFormName"

    }

  ) | ConvertTo-Json

 

  if ($body[0] -ne '[') {

    $body = "[" + $body + "]"

  }

 

  Write-DebugMsg "Trying platformId-only PATCH"

  Write-DebugMsg "URI: $apiUrl"

  Write-DebugMsg "Body: $body"

 

  Invoke-RestMethod `

    -Uri $apiUrl `

    -Method Patch `

    -Headers $headers `

    -Body $body `

    -ContentType "application/json" | Out-Null

}"

1 accepted solution

Accepted Solutions

Check the response body, it should tell you why the API rejected the request.

$Result = Invoke-RestMethod .... Write-Host $Result

A common error happens when you want to change an account's platform to a new platform that has a different "Device Type" - see: https://community.cyberark.com/s/question/0D52J000096sesoSAA/how-to-move-an-account-to-a-different-platform-its-not-letting-me

As far as I can tell, there is no way to do this via REST API in PrivCloud, as of right now.

View solution in original post

4 REPLIES 4

L0 Member

Take a look at your $body. Might want to simplify. I would eliminate the ConvertTo-Json and array notation. @( )

$body = {

"op" : "replace"

"path" : "/platformID"

"value" : "NewPlatformName"

}

 

See if that helps. Do a web search for REST API body json Plenty out there to help.

I updated my script to the below, unfortunately same error.

 

function Set-PlatformId {

  param(

    [Parameter(Mandatory)]

    [string]$AccountId,

 

    [Parameter(Mandatory)]

    [string]$PlatformId

  )

 

  $uri = "$PCloudURL/API/Accounts/$AccountId"

 

  $body = '[{"op":"replace","path":"/platformId","value":"' + $PlatformId + '"}]'

 

  Write-Host "PATCH $uri"

  Write-Host "Body: $body" -ForegroundColor Cyan

 

  Invoke-RestMethod -Uri $uri -Method Patch -Headers @{

    Authorization = $headers.Authorization

    "Content-Type" = "application/json"

  } -Body $body

}

Check the response body, it should tell you why the API rejected the request.

$Result = Invoke-RestMethod .... Write-Host $Result

A common error happens when you want to change an account's platform to a new platform that has a different "Device Type" - see: https://community.cyberark.com/s/question/0D52J000096sesoSAA/how-to-move-an-account-to-a-different-platform-its-not-letting-me

As far as I can tell, there is no way to do this via REST API in PrivCloud, as of right now.

Yup, found that out yesterday. You can only change device type on v1 and that only works for on-prem unfortunately. Thanks everyone for the insight.

  • 1 accepted solution
  • 58 Views
  • 4 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!