---
title: Save New Device Realms
slug: single-connect-api-3-2-0/save-new-device-realms
description: Learn how to use the curl command to make a POST request and save device realms with this helpful code example. Find step-by-step instructions on adding headers to accept and send JSON data, and discover how to set the request body as a string. Perfect fo
docTags: 
createdAt: 2022-11-10T14:24:52.000Z
---

{
  "id": "_QFvGQV2gOt16zk6Qm8kV",
  "data": {
    "url": "{{url}}/aioc-rest-web/rest/discovery/saveDeviceRealms",
    "method": "POST",
    "request": {
      "pathParameters": [],
      "queryParameters": [],
      "headerParameters": [
        {
          "name": "Content-Type",
          "type": "string",
          "example": "application/json",
          "description": ""
        },
        {
          "name": "X-XSRF-TOKEN",
          "type": "string",
          "example": "{{csrftoken}}",
          "description": ""
        }
      ],
      "bodyDataParameters": [
        {
          "name": "body",
          "type": "string",
          "example": "[   {\n        \n        \"name\": \"TEST_DeviceRealm\",\n        \"description\": \"TEST_DeviceRealm\",\n        \"deviceGroups\": [\n            {\n                \"dbId\": 303871,\n                \"id\": \"feba5a25-7f1b-462e-bb45-711a27783cb0\"\n            },\n            {\n            \t \"dbId\": 303880,\n                \"id\": \"7dad2aa5-414a-4b20-86c0-346876ea88b5\"\n            }\n        ],\n        \"userGroups\": [\n            {\"id\": \"57888613-58bd-4008-af8a-729dc53edbed\",\n                \"eid\": \"SshUG1\"}\n        ]\n    }\n]",
          "description": ""
        }
      ],
      "formDataParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "saveDeviceRealms",
        "jsonExample": "{\n    \"TEST_DeviceRealm\": \"Success\"\n}"
      },
      {
        "statusCode": "200",
        "description": "<p>ex2_saveDeviceRealms</p>",
        "jsonExample": "{\n    \"TEST_DeviceRealm\": \"Success\"\n}"
      },
      {
        "statusCode": "200",
        "description": "<p>ex3_saveDeviceRealms</p>",
        "jsonExample": "{\n    \"TEST_DeviceRealm\": \"Success\"\n}"
      }
    ],
    "contentType": "application/json",
    "description": "<p>This method adds a new device realm to Single Connect.</p>\n<p>Mandatory fields:</p>\n<p>\"name\":</p>\n<p>\"deviceGroups\": [\n{\n\"dbId\": }]</p>\n<p>\"userGroups\": [\n{\"id\": \"\"}</p>\n<p>Other fields can be removed.</p>",
    "examples": {
      "languages": [
        {
          "id": "ZD0LrquvX4R6z0O_60P1j",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url {{url}}/aioc-rest-web/rest/discovery/saveDeviceRealms \\\n     --header 'accept: application/json'"
        },
        {
          "id": "nyguPMSKgmDu_NDTXP0aO",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"{{url}}/aioc-rest-web/rest/discovery/saveDeviceRealms\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "wH-WgpHDlMSB_mE4U3IT8",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"{{url}}/aioc-rest-web/rest/discovery/saveDeviceRealms\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "3DSDD_Gz4mF9uPvLyw9nJ",
          "language": "python",
          "label": "Python",
          "code": "import requests\n\nurl = \"{{url}}/aioc-rest-web/rest/discovery/saveDeviceRealms\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "ZD0LrquvX4R6z0O_60P1j"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "{\n    \"TEST_DeviceRealm\": \"Success\"\n}"
        },
        {
          "id": "response-1-200",
          "language": "200",
          "code": "{\n    \"TEST_DeviceRealm\": \"Success\"\n}"
        },
        {
          "id": "response-2-200",
          "language": "200",
          "code": "{\n    \"TEST_DeviceRealm\": \"Success\"\n}"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "type": "api-oas-v2",
  "children": [
    {
      "text": ""
    }
  ]
}