Skip to content
Docs
Roles

Create role

Create role

zones.roles.create(strzone_id, RoleCreateParams**kwargs) -> Role
POST/zones/{zoneId}/roles

Creates a new customer-owned role in the specified zone. The owner_type is always customer; platform roles are managed by Keycard.

ParametersExpand Collapse
zone_id: str
identifier: str

Role identifier: a lowercase slug (letters and digits separated by single hyphens or underscores), unique per owner type within a zone. Role identifiers surface in policy evaluation, so the slug restriction keeps them unambiguous in policy text.

minLength1
maxLength255
description: Optional[str]

Human-readable description

maxLength1000
ReturnsExpand Collapse
class Role:

A role that can be assigned to users within a zone.

id: str

Unique identifier of the role

created_at: datetime

Entity creation timestamp

formatdate-time
identifier: str

Role identifier: a lowercase slug (letters and digits separated by single hyphens or underscores), unique per owner type within a zone. Role identifiers surface in policy evaluation, so the slug restriction keeps them unambiguous in policy text.

minLength1
maxLength255
owner_type: Literal["platform", "customer"]

Who owns this role. Platform-owned roles are managed by Keycard and cannot be modified or deleted via the API; customer-owned roles are user-created.

Accepts one of the following:
"platform"
"customer"
updated_at: datetime

Entity update timestamp

formatdate-time
zone_id: str

Zone this role belongs to

description: Optional[str]

Human-readable description

maxLength1000

Create role

import os
from keycardai_api import KeycardAPI

client = KeycardAPI(
    api_key=os.environ.get("KEYCARD_API_API_KEY"),  # This is the default and can be omitted
)
role = client.zones.roles.create(
    zone_id="zoneId",
    identifier="identifier",
)
print(role.id)
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "identifier": "identifier",
  "owner_type": "platform",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "zone_id": "zone_id",
  "description": "description"
}
Returns Examples
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "identifier": "identifier",
  "owner_type": "platform",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "zone_id": "zone_id",
  "description": "description"
}