REST API to disable a policy

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

REST API to disable a policy

L2 Linker

FFS. I feel like this is a straightforward request, but no matter what I do, I can't get the frustrating "update policy" REST API to work.

 

I did the needful, logged in, get the policy information details:

 

$newPolicyURL = $managerServer + "epm/api/sets/" + $allsets.Sets[1].id + "/policies/Server/" + $response.Policies[0].PolicyId

 

I then tried to create a custom JSON, it didn't work.

 

I tried passing back the original result from the Policy Details call, and got this message:

Invoke-RestMethod : [{"Fields":["policy"],"ErrorCode":"EPM000002E","ErrorMessage":"Missing mandatory parameter - policy."}]

 

Anyone got any suggestions?

 

9 REPLIES 9

L5 Sessionator

Hi @Carl Chipman​ ,

 

Are you trying to update or create new policy ?

Can you share the request ?

 

 

Thanks,

Arik.

 

 

 

 

L2 Linker

I'm trying to update it from Enabled to Disabled. I've had to reboot since I last tried it, so I'd have to go recreated the, but I even basically did

 

Get the policy

Change the Policy Setting for enabled to $false

Try to update the policy

L2 Linker

I would really like it if *someone* could just post the code for "disable an existing policy" with the REST API.

L5 Sessionator

Hi @Carl Chipman​ ,

 

Note there is a small change you need to do except changing the "IsActive".

When you run the get the policy you get the response which looks like that

{

 "Policy": {

  "Id": "64d66c43-29ca-4e27-b0fe-c8e530xxxxx",

  "Name": "Policy by API",

  "PolicyType": 12,

  "Action": 3,

  "Audit": false,

  "Applications": [

.

.

}

}

 

However, when running the update call you need to take the internal part of the policy.

it should look like that -

 

 {

    "Id": "64d66c43-29ca-4e27-b0fe-c8e5301xxxxx",

  "Name": "Policy by API",

  "PolicyType": 12,

  "Action": 3,

  "Audit": false,

  "Applications": [

   {

    "id": "433441a1-e057-42f5-b0ec-eyyyyyyy",

    "internalId": 0,

    "applicationType": 28,

    "displayName": "",

    "description": "",

    "patterns": {

     "FILE_NAME": {

      "@type": "FileName",

      "hashAlgorithm": "SHA1",

      "hash": "873344171d75b28fdf3ec1797272d885135e6628",

      "hashSHA256": "",

      "fileSize": 0,

      "isEmpty": false,

      "content": "dnf-3",

      "compareAs": 0,

      "caseSensitive": true

     },

     "ARGUMENTS": {

      "@type": "Text",

      "content": "",

      "compareAs": 0,

      "caseSensitive": true,

      "onlyEmptyValue": false,

      "isEmpty": true

     },

     "LOCATION": {

      "@type": "Location",

      "content": "/usr/bin/",

      "withSubfolders": true,

      "caseSensitive": true,

      "isEmpty": false

     },

     "LINUX_LINK_NAME": {

      "@type": "Text",

      "content": "yum",

      "compareAs": 0,

      "caseSensitive": true,

      "isEmpty": false

     },

     "LINUX_SCRIPT_INTERPRETER": {

      "@type": "TextArray",

      "separator": ";",

      "content": "/usr/bin/python3",

      "compareAs": 0,

      "caseSensitive": true,

      "isEmpty": false

     },

     "LINUX_RUN_AS_USER": {

      "@type": "LinuxRunAsUser",

      "users": [

       "root"

      ],

      "compareAs": 0,

      "isEmpty": false

     }

    },

    "applicationGroupId": "00000000-0000-0000-0000-000000000000",

    "internalApplicationGroupId": 0,

    "includeInMatching": true,

    "accountId": "00000000-0000-0000-0000-000000000000",

    "LinuxChildProcess": 1,

    "restrictOpenSaveFileDialog": false,

    "securityTokenId": "00000000-0000-0000-0000-000000000000",

    "protectInstalledFiles": false,

    "linuxSudoNoPassword": false

   }

  ],

  "Activation": null,

  "Priority": 40,

  "Executors": [],

  "IsAppliedToAllComputers": true,

  "Accounts": [],

  "IncludeADComputerGroups": [],

  "ExcludeADComputerGroups": [],

  "Description": "",

  "IsActive": false,

  "LinkedAgentPolicies": [

   {

    "Id": "64d66c43-29ca-4e27-b0fe-c8ezzzzzzzz",

    "InternalId": 955555,

    "PolicyType": 4003,

    "DefaultApplicationGroupId": "00000000-0000-0000-0000-000000000000"

   }

  ]

 }

 }

 

 

Thanks,

Arik.

 

L2 Linker

Thanks Arik. I'll give that a try.

 

L2 Linker

ok, so I went back to bare bones, and used the get- policies details, and modified the policy part of the JSON, and got this JSON:

 

{

 "Id": "41ba3e3b-3c8d-4d60-a641-2f6e545b24da",

 "Name": "CARL-ELEVATE",

 "PolicyType": 11,

 "Action": 3,

 "UIOnStart": {

  "Id": "aaeb70cd-0643-4baf-8cf5-ccda845b1828",

  "AllowedDialogType": "Elevate"

 },

--snip a lot of stuff --

 },

 "IncludeADComputerGroups": [],

 "ExcludeADComputerGroups": [],

 "Description": "",

 "IsActive": false,

 "LinkedAgentPolicies": [

  {

   "Id": "7f75e155-9cd1-4e11-b376-dd842ec9c235",

   "InternalId": 766045,

   "PolicyType": 3,

   "DefaultApplicationGroupId": "00000000-0000-0000-0000-000000000000"

  }

 ]

}

 

I then called the update, using this:

 

foreach ($policy in $customPolicies) { # Output the current policy being processed Write-Host "Gathering information on $($policy.PolicyName)" -NoNewline   # Construct the URL to retrieve details for the current policy $policiesDetailsURL = $managerServer + "/epm/api/sets/" + $caset.Id + "/policies/server/" + $policy.PolicyId   # Send a GET request to the policies details URL to retrieve the policy details $response = Invoke-RestMethod $policiesDetailsURL -Method 'GET' -Headers $headers   #$policy.IsActive = $false $response.Policy.IsActive = $false $UpdatePolicyURL = $managerServer + "/epm/api/sets/" + $caset.Id + "/policies/server/" + $policy.PolicyId # Send an PUT method to update the policy to be inactive $body = ($response.Policy | ConvertTo-Json -Depth 10) $response = Invoke-RestMethod $UpdatePolicyURL -Method 'PUT' -Headers $headers -Body $body   # Output a message indicating the completion of pulling application group details for the current group Write-Host "-Done. Sleeping for about 3 seconds" Start-Sleep -Milliseconds 3200 }

and I get this message:

 

Line |

 79 | … $response = Invoke-RestMethod $UpdatePolicyURL -Method 'PUT' -Headers …

   |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   | [  {   "ErrorCode": "EPM000004E",   "ErrorMessage": "The requested resource could not be found, or the user does not have permissions for this  

   | resource."  } ]

 

L2 Linker

ok, weird followup. This code works in disabling the policy although the error message is still thrown.

 

L4 Transporter

Hello @Carl Chipman​ 

 

Have you received an answer to your question? If so, we kindly encourage you to share it with us.

Your insights could be valuable to other community members in the future.

 

Thank you, Isar.

Dude, literally, there is an update 7 hours prior to your template question. I've made progress, but it's not a solution. PLEASE, FFS, help us get some developer support.

  • 108 Views
  • 9 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!