syntax issue with body parameter of invoke rest method patch

Welcome Forums General PowerShell Q&A syntax issue with body parameter of invoke rest method patch

Viewing 2 reply threads
  • Author
    Posts
    • #233740
      Participant
      Topics: 11
      Replies: 9
      Points: 110
      Rank: Participant
      I am getting below error message for Invoke-RestMethod with PATCH method type
      Invoke-RestMethod : {“detail”:”Received JSON for the roles attribute does not match expected
      format.”,”error”:400,”errorCode”:”INVALID_JSON_ATTRIBUTE”,”parameters”:[“roles”],”reason”:”Bad Request”}
      Can some one let me know the mistake with below code please?
      if ($atlasdbname -contains $dbname)
       {
      $dbnew = @{
                     roles = $rolnew}
      $dbupdate = $dbnew | ConvertTo-Json
        Invoke-RestMethod -Method PATCH -Uri $prjuri -Headers @{Authorization = “Basic $base64AuthInfo”} -ContentType “application/json” -Credential $credential -Body $dbupdate
      Thanks
      • This topic was modified 1 month, 1 week ago by pk30.
    • #233743
      Participant
      Topics: 11
      Replies: 9
      Points: 110
      Rank: Participant

      Got it resolved , Thanks

      roles = @($rolnew)

       

    • #234727
      Participant
      Topics: 0
      Replies: 1
      Points: 6
      Rank: Member

      Thanks for your solution!

      Hopefully this helps somebody else get the rest of the way if they are having issues whitelisting:

      $Whitelist = @{“cidrBlock”=”$IpRange”;”comment”=”Testing”}

      $NewListing = @($Whitelist)

      $BodyJSON = ConvertTo-Json -InputObject $NewListing
      Invoke-RestMethod -Uri  $AtlasURI -Method Post -ContentType “application/json” -Body $BodyJSON -Credential $Credential
Viewing 2 reply threads
  • You must be logged in to reply to this topic.