Skip to content
Start here

List policy sets

client.ZeroTrust.CWS.PolicySets.List(ctx, params) (*CursorPagination[PolicySet], error)
GET/accounts/{account_id}/cws/policy-sets

Returns a paginated list of policy sets in the account.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
params CWSPolicySetListParams
AccountID param.Field[string]

Path param: Cloudflare account ID (32-character hexadecimal string)

maxLength32
minLength32
Cursor param.Field[string]Optional

Query param: Pagination cursor from previous response

DeploymentID param.Field[string]Optional

Query param: Filter to policy sets attached to this deployment

formatuuid
Direction param.Field[CWSPolicySetListParamsDirection]Optional

Query param: Sort direction (default: asc)

const CWSPolicySetListParamsDirectionAsc CWSPolicySetListParamsDirection = "asc"
const CWSPolicySetListParamsDirectionDesc CWSPolicySetListParamsDirection = "desc"
Name param.Field[string]Optional

Query param: Filter by policy set name (case-insensitive substring match)

Order param.Field[CWSPolicySetListParamsOrder]Optional

Query param: Field to order results by (default: created_at)

const CWSPolicySetListParamsOrderName CWSPolicySetListParamsOrder = "name"
const CWSPolicySetListParamsOrderCreatedAt CWSPolicySetListParamsOrder = "created_at"
const CWSPolicySetListParamsOrderUpdatedAt CWSPolicySetListParamsOrder = "updated_at"
PerPage param.Field[int64]Optional

Query param: Number of items per page (1-100, default 20)

formatint64
maximum100
minimum1
ReturnsExpand Collapse
type PolicySet struct{…}
ID string

Server-assigned UUID

formatuuid
CreatedAt Time
formatdate-time
ExcludeWorkloadIDs []string

IDs of workloads that exclude matching requests. Exclusions take precedence.

IncludeWorkloadIDs []string

IDs of workloads that include matching requests. Empty includes all requests before exclusions.

Name string

Human-readable name; unique per account

maxLength100
minLength1
Policies []PolicySetPolicy

Member policies and their per-membership enforcement mode

Enforce bool

Whether this policy should enforce when it matches. False keeps the policy attached for non-enforcing evaluation.

PolicyID string

ID of the member policy

formatuuid
Tags map[string, string]

Tags attached to this policy set

UpdatedAt Time
formatdate-time
Description stringOptional

Optional free-form description.

maxLength1024

List policy sets

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
  "github.com/cloudflare/cloudflare-go/zero_trust"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  page, err := client.ZeroTrust.CWS.PolicySets.List(context.TODO(), zero_trust.CWSPolicySetListParams{
    AccountID: cloudflare.F("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
{
  "errors": [
    {
      "code": 0,
      "message": "message",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": [
    {
      "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
      "created_at": "2019-12-27T18:11:19.117Z",
      "exclude_workload_ids": [
        "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
      ],
      "include_workload_ids": [
        "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
      ],
      "name": "x",
      "policies": [
        {
          "enforce": true,
          "policy_id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
        }
      ],
      "tags": {
        "foo": "string"
      },
      "updated_at": "2019-12-27T18:11:19.117Z",
      "description": "description"
    }
  ],
  "result_info": {
    "count": 0,
    "per_page": 0,
    "total_count": 0,
    "cursor": "cursor"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 0,
      "message": "message",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": [
    {
      "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
      "created_at": "2019-12-27T18:11:19.117Z",
      "exclude_workload_ids": [
        "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
      ],
      "include_workload_ids": [
        "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
      ],
      "name": "x",
      "policies": [
        {
          "enforce": true,
          "policy_id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
        }
      ],
      "tags": {
        "foo": "string"
      },
      "updated_at": "2019-12-27T18:11:19.117Z",
      "description": "description"
    }
  ],
  "result_info": {
    "count": 0,
    "per_page": 0,
    "total_count": 0,
    "cursor": "cursor"
  },
  "success": true
}