Skip to content
API Reference

Create a new policy

client.Zones.Policies.New(ctx, zoneID, params) (*Policy, error)
POST/zones/{zone_id}/policies

Create a new policy

ParametersExpand Collapse
zoneID string
params ZonePolicyNewParams
Name param.Field[string]

Body param

Description param.Field[string]optional

Body param

XAPIVersion param.Field[string]optional

Header param: API version header (date-based, e.g. 2026-02-01)

XClientRequestID param.Field[string]optional

Header param: Unique request identifier specified by the originating caller and passed along by proxies.

formatuuid
ReturnsExpand Collapse
type Policy struct{…}
ID string
CreatedAt Time
formatdate-time
CreatedBy string
Name string
OwnerType PolicyOwnerType

Who manages this policy:

  • "platform" — managed by the Keycard platform (system policies).
  • "customer" — managed by the tenant (custom policies).
Accepts one of the following:
const PolicyOwnerTypePlatform PolicyOwnerType = "platform"
const PolicyOwnerTypeCustomer PolicyOwnerType = "customer"
UpdatedAt Time
formatdate-time
ZoneID string
ArchivedAt Timeoptional
formatdate-time
Description stringoptional
LatestVersion int64optional

Human-readable version number of the latest version (e.g., 1, 2, 3)

LatestVersionID stringoptional
UpdatedBy stringoptional

Create a new policy

package main

import (
  "context"
  "fmt"

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

func main() {
  client := keycard.NewClient(

  )
  policy, err := client.Zones.Policies.New(
    context.TODO(),
    "zone_id",
    keycard.ZonePolicyNewParams{
      Name: "name",
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", policy.ID)
}
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "created_by": "created_by",
  "name": "name",
  "owner_type": "platform",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "zone_id": "zone_id",
  "archived_at": "2019-12-27T18:11:19.117Z",
  "description": "description",
  "latest_version": 0,
  "latest_version_id": "latest_version_id",
  "updated_by": "updated_by"
}
Returns Examples
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "created_by": "created_by",
  "name": "name",
  "owner_type": "platform",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "zone_id": "zone_id",
  "archived_at": "2019-12-27T18:11:19.117Z",
  "description": "description",
  "latest_version": 0,
  "latest_version_id": "latest_version_id",
  "updated_by": "updated_by"
}