---
title: Save/Update Device Realm With Policy Groups
slug: kron-pam-api-collection-3-9-0/saveupdate-device-realm-with-policy-groups
docTags: 
createdAt: 2026-10-21T06:10:28.166Z
---

{
  "id": "a9HtptFxcdgzCMA-iSoQh",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "{{url}}/aioc-rest-web/rest/discovery/ui/saveDeviceRealmsWithPolicyGroups",
    "name": "",
    "description": "<h3>Request Overview</h3>\n<p>The <strong>Save/Update Device Realm With Policy Groups</strong> method is the combined endpoint the current PAM web UI uses to add or edit a Device Realm together with its Single Connect Policy Group linkage (Policy Enforcement must be enabled). This is the endpoint that changed/was added in newer PAM versions relative to the plain <code>saveDeviceRealms</code>/<code>updateDeviceRealms</code> pair, and is the one to use for the full add/edit Realm flow when policy groups are involved.</p>\n<h4>Behavior:</h4>\n<ul>\n<li><code>dbId</code> absent/null on the realm object -> <strong>create</strong> a new device realm.</li>\n<li><code>dbId</code> set -> <strong>update</strong> the existing device realm.</li>\n<li>For each entry in <code>policyKeyRealms</code> (existing Policy Realm dbIds), the linked Policy Realm's Policy Groups are replaced with the <code>policyGroups</code> supplied. If <code>policyKeyRealms</code> is empty, a brand-new Policy Realm is created and linked to this device realm using the supplied <code>policyGroups</code>.</li>\n</ul>\n<h4>Required Fields:</h4>\n<pre><code class=\"language-json\">{\n  \"name\": \"&#x3C;name of the realm>\",\n  \"deviceGroups\": [ { \"dbId\": \"&#x3C;device group ID>\" } ],\n  \"userGroups\": [ { \"id\": \"&#x3C;user group ID>\" } ],\n  \"policyGroups\": [ { \"dbId\": \"&#x3C;policy group ID>\" } ],\n  \"policyKeyRealms\": [ \"&#x3C;existing Policy Realm dbId, or empty to auto-create>\" ]\n}\n\n</code></pre>",
    "contentType": "application/json",
    "request": {
      "headerParameters": [
        {
          "name": "Content-Type",
          "description": "",
          "default": "application/json",
          "value": "application/json",
          "type": "string"
        },
        {
          "name": "X-XSRF-TOKEN",
          "description": "",
          "default": "{{csrftoken}}",
          "value": "{{csrftoken}}",
          "type": "string"
        }
      ],
      "queryParameters": [],
      "pathParameters": [
        {
          "name": "url",
          "description": "",
          "default": "url",
          "value": "url",
          "type": "string"
        }
      ],
      "bodyDataParameters": [
        {
          "name": "body",
          "description": "",
          "default": "[\n    {\n        \"dbId\": null,\n        \"name\": \"TEST_DeviceRealm_PG\",\n        \"description\": \"TEST_DeviceRealm_PG\",\n        \"deviceGroups\": [\n            {\n                \"dbId\": 303871,\n                \"id\": \"feba5a25-7f1b-462e-bb45-711a27783cb0\"\n            }\n        ],\n        \"userGroups\": [\n            {\n                \"id\": \"57888613-58bd-4008-af8a-729dc53edbed\",\n                \"eid\": \"SshUG1\"\n            }\n        ],\n        \"policyGroups\": [\n            {\n                \"dbId\": 12,\n                \"name\": \"PG_SSH_Admins\"\n            }\n        ],\n        \"policyKeyRealms\": []\n    }\n]",
          "value": "[\n    {\n        \"dbId\": null,\n        \"name\": \"TEST_DeviceRealm_PG\",\n        \"description\": \"TEST_DeviceRealm_PG\",\n        \"deviceGroups\": [\n            {\n                \"dbId\": 303871,\n                \"id\": \"feba5a25-7f1b-462e-bb45-711a27783cb0\"\n            }\n        ],\n        \"userGroups\": [\n            {\n                \"id\": \"57888613-58bd-4008-af8a-729dc53edbed\",\n                \"eid\": \"SshUG1\"\n            }\n        ],\n        \"policyGroups\": [\n            {\n                \"dbId\": 12,\n                \"name\": \"PG_SSH_Admins\"\n            }\n        ],\n        \"policyKeyRealms\": []\n    }\n]",
          "type": "object"
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "saveDeviceRealmsWithPolicyGroups",
        "jsonExample": "{\n    \"TEST_DeviceRealm_PG\": \"Success\"\n}"
      }
    ],
    "examples": {
      "languages": [
        {
          "id": "WAiwzp05ora95jB9J2fuV",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url {{url}}/aioc-rest-web/rest/discovery/ui/saveDeviceRealmsWithPolicyGroups \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --header 'x-xsrf-token: {{csrftoken}}' \\\n     --data '\"[\\n    {\\n        \\\"dbId\\\": null,\\n        \\\"name\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"description\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"deviceGroups\\\": [\\n            {\\n                \\\"dbId\\\": 303871,\\n                \\\"id\\\": \\\"feba5a25-7f1b-462e-bb45-711a27783cb0\\\"\\n            }\\n        ],\\n        \\\"userGroups\\\": [\\n            {\\n                \\\"id\\\": \\\"57888613-58bd-4008-af8a-729dc53edbed\\\",\\n                \\\"eid\\\": \\\"SshUG1\\\"\\n            }\\n        ],\\n        \\\"policyGroups\\\": [\\n            {\\n                \\\"dbId\\\": 12,\\n                \\\"name\\\": \\\"PG_SSH_Admins\\\"\\n            }\\n        ],\\n        \\\"policyKeyRealms\\\": []\\n    }\\n]\"'"
        },
        {
          "id": "u_gXViTAYowVQCmE0miEk",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\nmyHeaders.append(\"x-xsrf-token\", \"{{csrftoken}}\");\n\nvar raw = JSON.stringify(\"[\\n    {\\n        \\\"dbId\\\": null,\\n        \\\"name\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"description\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"deviceGroups\\\": [\\n            {\\n                \\\"dbId\\\": 303871,\\n                \\\"id\\\": \\\"feba5a25-7f1b-462e-bb45-711a27783cb0\\\"\\n            }\\n        ],\\n        \\\"userGroups\\\": [\\n            {\\n                \\\"id\\\": \\\"57888613-58bd-4008-af8a-729dc53edbed\\\",\\n                \\\"eid\\\": \\\"SshUG1\\\"\\n            }\\n        ],\\n        \\\"policyGroups\\\": [\\n            {\\n                \\\"dbId\\\": 12,\\n                \\\"name\\\": \\\"PG_SSH_Admins\\\"\\n            }\\n        ],\\n        \\\"policyKeyRealms\\\": []\\n    }\\n]\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"{{url}}/aioc-rest-web/rest/discovery/ui/saveDeviceRealmsWithPolicyGroups\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "epOQT36W5Z0s2jLTtJAKH",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"{{url}}/aioc-rest-web/rest/discovery/ui/saveDeviceRealmsWithPolicyGroups\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest[\"x-xsrf-token\"] = \"{{csrftoken}}\"\nrequest.body = JSON.dump(\"[\\n    {\\n        \\\"dbId\\\": null,\\n        \\\"name\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"description\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"deviceGroups\\\": [\\n            {\\n                \\\"dbId\\\": 303871,\\n                \\\"id\\\": \\\"feba5a25-7f1b-462e-bb45-711a27783cb0\\\"\\n            }\\n        ],\\n        \\\"userGroups\\\": [\\n            {\\n                \\\"id\\\": \\\"57888613-58bd-4008-af8a-729dc53edbed\\\",\\n                \\\"eid\\\": \\\"SshUG1\\\"\\n            }\\n        ],\\n        \\\"policyGroups\\\": [\\n            {\\n                \\\"dbId\\\": 12,\\n                \\\"name\\\": \\\"PG_SSH_Admins\\\"\\n            }\\n        ],\\n        \\\"policyKeyRealms\\\": []\\n    }\\n]\")\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "5pHyw6ZhqxO27DwOlKGc9",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"{{url}}/aioc-rest-web/rest/discovery/ui/saveDeviceRealmsWithPolicyGroups\"\n\npayload = json.dumps(\"[\\n    {\\n        \\\"dbId\\\": null,\\n        \\\"name\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"description\\\": \\\"TEST_DeviceRealm_PG\\\",\\n        \\\"deviceGroups\\\": [\\n            {\\n                \\\"dbId\\\": 303871,\\n                \\\"id\\\": \\\"feba5a25-7f1b-462e-bb45-711a27783cb0\\\"\\n            }\\n        ],\\n        \\\"userGroups\\\": [\\n            {\\n                \\\"id\\\": \\\"57888613-58bd-4008-af8a-729dc53edbed\\\",\\n                \\\"eid\\\": \\\"SshUG1\\\"\\n            }\\n        ],\\n        \\\"policyGroups\\\": [\\n            {\\n                \\\"dbId\\\": 12,\\n                \\\"name\\\": \\\"PG_SSH_Admins\\\"\\n            }\\n        ],\\n        \\\"policyKeyRealms\\\": []\\n    }\\n]\")\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json',\n   'x-xsrf-token': '{{csrftoken}}'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "WAiwzp05ora95jB9J2fuV"
    },
    "results": {
      "languages": [
        {
          "id": "_l5j7tgifmE86a-HzthI9",
          "language": "200",
          "code": "{\n    \"TEST_DeviceRealm_PG\": \"Success\"\n}"
        }
      ],
      "selectedLanguageId": "_l5j7tgifmE86a-HzthI9"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}