Update Account does not accept the JSON body

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

Welcome Idira to LIVEcommunity!

Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.

Meet Idira

Update Account does not accept the JSON body

L3 Networker

I follow the example from body parameters. When I split it up, one gets the following structure:

[ { "op": "replace", "path": "/address", "value": "10.10.27.254" }, { "op": "replace", "path": "/secretManagement/automaticManagementEnabled", "value": "false" } ]

My body looks:

[ { "op": "Replace", "path": "/address", "value": "10.10.10.10" } ]

The error message I receive is:

"The parameters dictionary contains an invalid entry for parameter 'actionParameters' for method 'System.Net.Http.HttpResponseMessage [...] The dictionary contains a value of type 'Newtonsoft.Json.Linq.JArray', but the parameter requires a value of type 

'Newtonsoft.Json.Linq.JObject'."

 

The line to create the body variable is:

$body = ConvertTo-Json -Depth 2 -InputObject @( [PSCustomObject] @{ op = $Operation; path = "/$Path"; value = $Value; } )

Where could be the error? Should the body have a different JSON structure?

 

1 accepted solution

Accepted Solutions

L3 Networker

The error was actually not in the body but in the Method I used. As the documentation did not mention the method I assumed "POST" should be used but looking at the unofficial CyberArk REST API "PATCH" is the method to use.

 

Below is the working API call (The session variable carries the Authentication and Content-Type keys).

Invoke-RestMethod -Method Patch -Uri $url -Body $body -WebSession $Session

 

View solution in original post

4 REPLIES 4

L4 Transporter

Hi @Alexander Piepenhagen​ 

 

Not sure about this, but try lowercase "Replace" -> meaning "replace"

 

one other thing, related to the error you mentioned.

I think you should split the line into two steps:

creating this (similar to what you posted):

PS > $a = @( @{ op="replace";path="/address";value="10.10.10.10"})

PS > $a | ConvertTo-Json

{

  "path": "/address",

  "op": "replace",

  "value": "10.10.10.10"

}

 

is creating a JSON object, not an Array like in the example

Try using:

$array = @()

$body = "" | select op, path, value

$body.op = "replace"

$body.path = "/address"

$body.value = "10.10.10.10"

$array += $body

$array | ConvertTo-JSON

 

Hope this helps,

Assaf

L3 Networker

The error was actually not in the body but in the Method I used. As the documentation did not mention the method I assumed "POST" should be used but looking at the unofficial CyberArk REST API "PATCH" is the method to use.

 

Below is the working API call (The session variable carries the Authentication and Content-Type keys).

Invoke-RestMethod -Method Patch -Uri $url -Body $body -WebSession $Session

 

L4 Transporter

Great to hear that this resolved the issue 🙂

by the way, in the official documentation this is also written see:

https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/UpdateAccount%20v10.htm#Resourceinformation

Ah, now I see it too. Because of the bold font I disregarded it as a header. I only saw the 'Content type' row 😄

  • 1 accepted solution
  • 658 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!