# Roles

## List

`client.Zones.Applications.Roles.List(ctx, applicationID, params) (*ZoneApplicationRoleListResponse, error)`

**get** `/zones/{zoneId}/applications/{applicationId}/roles`

Returns the roles assigned to the specified application within the zone. The full result set is currently returned in a single page; the `after`/`before`/`limit` cursor parameters are reserved and not yet enforced, and `pagination` cursors are always null.

### Parameters

- `applicationID string`

- `params ZoneApplicationRoleListParams`

  - `ZoneID param.Field[string]`

    Path param: Zone ID

  - `After param.Field[string]`

    Query param: Cursor for forward pagination

  - `Before param.Field[string]`

    Query param: Cursor for backward pagination

  - `Expand param.Field[ZoneApplicationRoleListParamsExpandUnion]`

    Query param

    - `type ZoneApplicationRoleListParamsExpandString string`

      - `const ZoneApplicationRoleListParamsExpandStringTotalCount ZoneApplicationRoleListParamsExpandString = "total_count"`

    - `type ZoneApplicationRoleListParamsExpandArray []string`

      - `const ZoneApplicationRoleListParamsExpandArrayItemTotalCount ZoneApplicationRoleListParamsExpandArrayItem = "total_count"`

  - `Limit param.Field[int64]`

    Query param: Maximum number of items to return

### Returns

- `type ZoneApplicationRoleListResponse struct{…}`

  - `Items []RoleAssignment`

    - `ID string`

      Unique identifier of the role assignment

    - `CreatedAt Time`

      Entity creation timestamp

    - `PrincipalID string`

      ID of the principal the role is assigned to (a user, application, or group ID).

    - `PrincipalType string`

      The kind of principal the role is assigned to: `user`, `application`, or `group`. A role assigned to a `group` is inherited by that group's members.

    - `RoleID string`

      ID of the assigned role

    - `RoleIdentifier string`

      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.

    - `RoleOwnerType RoleAssignmentRoleOwnerType`

      Owner type of the assigned role. Disambiguates roles that share an identifier across owner types.

      - `const RoleAssignmentRoleOwnerTypePlatform RoleAssignmentRoleOwnerType = "platform"`

      - `const RoleAssignmentRoleOwnerTypeCustomer RoleAssignmentRoleOwnerType = "customer"`

    - `UpdatedAt Time`

      Entity update timestamp

    - `ZoneID string`

      Zone this assignment belongs to

    - `ScopeID string`

      The ID of the scoped resource. Null when the assignment is unscoped.

    - `ScopeType string`

      The kind of resource this grant is scoped to (e.g. `zone`). Null when the assignment is unscoped (applies to the owning zone itself).

  - `Pagination ZoneApplicationRoleListResponsePagination`

    Cursor-based pagination metadata

    - `AfterCursor string`

      An opaque cursor used for paginating through a list of results

    - `BeforeCursor string`

      An opaque cursor used for paginating through a list of results

    - `TotalCount int64`

      Total number of items matching the query. Only included when expand[]=total_count is requested.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/keycardai/keycard-go"
  "github.com/keycardai/keycard-go/option"
)

func main() {
  client := keycard.NewClient(
    option.WithAPIKey("My API Key"),
  )
  roles, err := client.Zones.Applications.Roles.List(
    context.TODO(),
    "applicationId",
    keycard.ZoneApplicationRoleListParams{
      ZoneID: "zoneId",
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", roles.Items)
}
```

## Assign

`client.Zones.Applications.Roles.Assign(ctx, applicationID, params) (*RoleAssignment, error)`

**post** `/zones/{zoneId}/applications/{applicationId}/roles`

Assigns a role to the application. Provide exactly one of role_id or role_identifier; when role_identifier is used, owner_type is required to disambiguate roles that share an identifier across owner types (and must be omitted with role_id). An optional (scope_type, scope_id) pair scopes the grant; only platform roles on the org zone may carry a scope, and a `zone` scope must reference a different zone in the same organization.

### Parameters

- `applicationID string`

- `params ZoneApplicationRoleAssignParams`

  - `ZoneID param.Field[string]`

    Path param: Zone ID

  - `RoleAssignmentCreate param.Field[RoleAssignmentCreate]`

    Body param: Schema for assigning a role to a principal. Provide exactly one of role_id or role_identifier. When role_identifier is used, owner_type is required to disambiguate roles that share an identifier across owner types; owner_type must be omitted when role_id is used.

### Returns

- `type RoleAssignment struct{…}`

  Represents a role assigned to a principal within a zone

  - `ID string`

    Unique identifier of the role assignment

  - `CreatedAt Time`

    Entity creation timestamp

  - `PrincipalID string`

    ID of the principal the role is assigned to (a user, application, or group ID).

  - `PrincipalType string`

    The kind of principal the role is assigned to: `user`, `application`, or `group`. A role assigned to a `group` is inherited by that group's members.

  - `RoleID string`

    ID of the assigned role

  - `RoleIdentifier string`

    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.

  - `RoleOwnerType RoleAssignmentRoleOwnerType`

    Owner type of the assigned role. Disambiguates roles that share an identifier across owner types.

    - `const RoleAssignmentRoleOwnerTypePlatform RoleAssignmentRoleOwnerType = "platform"`

    - `const RoleAssignmentRoleOwnerTypeCustomer RoleAssignmentRoleOwnerType = "customer"`

  - `UpdatedAt Time`

    Entity update timestamp

  - `ZoneID string`

    Zone this assignment belongs to

  - `ScopeID string`

    The ID of the scoped resource. Null when the assignment is unscoped.

  - `ScopeType string`

    The kind of resource this grant is scoped to (e.g. `zone`). Null when the assignment is unscoped (applies to the owning zone itself).

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/keycardai/keycard-go"
  "github.com/keycardai/keycard-go/option"
)

func main() {
  client := keycard.NewClient(
    option.WithAPIKey("My API Key"),
  )
  roleAssignment, err := client.Zones.Applications.Roles.Assign(
    context.TODO(),
    "applicationId",
    keycard.ZoneApplicationRoleAssignParams{
      ZoneID: "zoneId",
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", roleAssignment.ID)
}
```

## Revoke

`client.Zones.Applications.Roles.Revoke(ctx, roleID, params) error`

**delete** `/zones/{zoneId}/applications/{applicationId}/roles/{roleId}`

Revokes a role from the application. Provide the same (scope_type, scope_id) pair the grant was created with, or omit both to revoke the unscoped grant.

### Parameters

- `roleID string`

- `params ZoneApplicationRoleRevokeParams`

  - `ZoneID param.Field[string]`

    Path param: Zone ID

  - `ApplicationID param.Field[string]`

    Path param: Application ID

  - `ScopeID param.Field[string]`

    Query param: Scope target of the grant to revoke. Provide together with scope_type.

  - `ScopeType param.Field[string]`

    Query param: Scope kind of the grant to revoke. Provide together with scope_id.

### Example

```go
package main

import (
  "context"

  "github.com/keycardai/keycard-go"
  "github.com/keycardai/keycard-go/option"
)

func main() {
  client := keycard.NewClient(
    option.WithAPIKey("My API Key"),
  )
  err := client.Zones.Applications.Roles.Revoke(
    context.TODO(),
    "roleId",
    keycard.ZoneApplicationRoleRevokeParams{
      ZoneID: "zoneId",
      ApplicationID: "applicationId",
    },
  )
  if err != nil {
    panic(err.Error())
  }
}
```
