---
title: Add permission to role
slug: api-documentation/add-permission-to-role
docTags: 
createdAt: 2026-08-27T17:06:32.549Z
---

{
  "id": "bHQHvgiRhUXZeyLhsQ4u4",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://api.upstartcommerce.com/profile-permissions/roles/{roleId}/permissions/{permissionName}",
    "servers": [
      {
        "url": "https://api.upstartcommerce.com/profile-permissions/roles/{roleId}/permissions/{permissionName}",
        "description": "Production"
      }
    ],
    "name": "Add permission to role",
    "description": "<p>Grants a permission to a role. Idempotent - no error if already granted.</p>\n<p><strong>Required Permission:</strong> <code>profile-permissions.roles.write</code></p>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "roleId",
          "type": "string",
          "description": "Role identifier"
        },
        {
          "kind": "required",
          "name": "permissionName",
          "type": "string",
          "description": "Permission name",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$"
        }
      ],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        }
      ],
      "queryParameters": [],
      "bodyDataParameters": [],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "bearerAuth",
          "name": "bearerAuth",
          "kind": "optional",
          "type": "http",
          "description": "<p>JWT token from authentication service.</p>\n<p>The token contains:</p>\n<ul>\n<li>sub: User ID</li>\n<li>tenant: Tenant ID (used for all operations)</li>\n<li>roles: Array of role IDs</li>\n<li>type: \"management\" or \"consumer\"</li>\n</ul>\n<p>Alternatively, tenant can be specified via X-Tenant-Id header.</p>",
          "scheme": "bearer"
        }
      ],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "<p>Permission added to role (or already present)</p>",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "401",
        "description": "Missing or invalid authentication token",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "<p>Error payload identifying the failure by error code and message, with optional detail.</p>",
            "customType": "ErrorResponse",
            "schema": [
              {
                "name": "error",
                "kind": "required",
                "type": "string<bad_request | unauthorized | forbidden | not_found | conflict | internal_error>",
                "description": "Error code",
                "example": "not_found",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "internal_error"
                ]
              },
              {
                "name": "message",
                "kind": "required",
                "type": "string",
                "description": "<p>Human-readable error message</p>",
                "example": "Role not found"
              },
              {
                "name": "details",
                "kind": "optional",
                "type": "map",
                "description": "Additional error details",
                "example": "",
                "customType": "map<string, string>",
                "schema": []
              }
            ],
            "modelRef": "#/components/schemas/ErrorResponse",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "404",
        "description": "Role or permission not found",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "<p>Error payload identifying the failure by error code and message, with optional detail.</p>",
            "customType": "ErrorResponse",
            "schema": [
              {
                "name": "error",
                "kind": "required",
                "type": "string<bad_request | unauthorized | forbidden | not_found | conflict | internal_error>",
                "description": "Error code",
                "example": "not_found",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "internal_error"
                ]
              },
              {
                "name": "message",
                "kind": "required",
                "type": "string",
                "description": "<p>Human-readable error message</p>",
                "example": "Role not found"
              },
              {
                "name": "details",
                "kind": "optional",
                "type": "map",
                "description": "Additional error details",
                "example": "",
                "customType": "map<string, string>",
                "schema": []
              }
            ],
            "modelRef": "#/components/schemas/ErrorResponse",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "500",
        "description": "Internal server error",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "<p>Error payload identifying the failure by error code and message, with optional detail.</p>",
            "customType": "ErrorResponse",
            "schema": [
              {
                "name": "error",
                "kind": "required",
                "type": "string<bad_request | unauthorized | forbidden | not_found | conflict | internal_error>",
                "description": "Error code",
                "example": "not_found",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "internal_error"
                ]
              },
              {
                "name": "message",
                "kind": "required",
                "type": "string",
                "description": "<p>Human-readable error message</p>",
                "example": "Role not found"
              },
              {
                "name": "details",
                "kind": "optional",
                "type": "map",
                "description": "Additional error details",
                "example": "",
                "customType": "map<string, string>",
                "schema": []
              }
            ],
            "modelRef": "#/components/schemas/ErrorResponse",
            "isExpanded": true
          }
        ]
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "LAZYIHpqYS9Y0xq-g913J",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://api.upstartcommerce.com/profile-permissions/roles/{roleId}/permissions/{permissionName} \\\n     --header 'accept: application/json'"
        },
        {
          "id": "S0t_mqy7sBSAeE5_rV358",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.upstartcommerce.com/profile-permissions/roles/{roleId}/permissions/{permissionName}\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "dkDCu7KoOXtrQWvlONF00",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api.upstartcommerce.com/profile-permissions/roles/{roleId}/permissions/{permissionName}\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "t6Et_MeZsmW7VeCeeefjj",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://api.upstartcommerce.com/profile-permissions/roles/{roleId}/permissions/{permissionName}\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "LAZYIHpqYS9Y0xq-g913J"
    },
    "results": {
      "languages": [
        {
          "id": "PAqDHFrOzuS8-eHMUDLwT",
          "language": "200",
          "code": "// Permission added to role (or already present)\n"
        },
        {
          "id": "BA1vHRn5W0jjBYDZuGsIg",
          "language": "401",
          "code": "// Missing or invalid authentication token\n{\n  \"error\": \"not_found\",\n  \"message\": \"Role not found\",\n  \"details\": \"\"\n}"
        },
        {
          "id": "-S8VPZ7h6QAsfYgw_Jr-W",
          "language": "404",
          "code": "// Role or permission not found\n{\n  \"error\": \"not_found\",\n  \"message\": \"Role not found\",\n  \"details\": \"\"\n}"
        },
        {
          "id": "dPJBsBjZfPwhe_wMnCueK",
          "language": "500",
          "code": "// Internal server error\n{\n  \"error\": \"not_found\",\n  \"message\": \"Role not found\",\n  \"details\": \"\"\n}"
        }
      ],
      "selectedLanguageId": "PAqDHFrOzuS8-eHMUDLwT"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}