Skip to content
Start here

List Tokens

client.User.Tokens.List(ctx, query) (*V4PagePaginationArray[Token], error)
GET/user/tokens

List all access tokens you created.

Security

API Token

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

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
Accepted Permissions (at least one required)
API Tokens WriteAPI Tokens Read
ParametersExpand Collapse
query TokenListParams
Direction param.Field[TokenListParamsDirection]optional

Direction to order results.

const TokenListParamsDirectionAsc TokenListParamsDirection = "asc"
const TokenListParamsDirectionDesc TokenListParamsDirection = "desc"
Page param.Field[float64]optional

Page number of paginated results.

minimum1
PerPage param.Field[float64]optional

Maximum number of results per page.

maximum50
minimum5
ReturnsExpand Collapse
type Token struct{…}
ID stringoptional

Token identifier tag.

maxLength32
Condition TokenConditionoptional
RequestIP TokenConditionRequestIPoptional

Client IP restrictions.

List of IPv4/IPv6 CIDR addresses.

NotIn []TokenConditionCIDRListoptional

List of IPv4/IPv6 CIDR addresses.

ExpiresOn Timeoptional

The expiration time on or after which the JWT MUST NOT be accepted for processing.

formatdate-time
IssuedOn Timeoptional

The time on which the token was created.

formatdate-time
LastUsedOn Timeoptional

Last time the token was used.

formatdate-time
ModifiedOn Timeoptional

Last time the token was modified.

formatdate-time
Name stringoptional

Token name.

maxLength120
NotBefore Timeoptional

The time before which the token MUST NOT be accepted for processing.

formatdate-time
Policies []TokenPolicyoptional

List of access policies assigned to the token.

ID string

Policy identifier.

Effect TokenPolicyEffect

Allow or deny operations against the resources.

One of the following:
const TokenPolicyEffectAllow TokenPolicyEffect = "allow"
const TokenPolicyEffectDeny TokenPolicyEffect = "deny"
PermissionGroups []TokenPolicyPermissionGroup

A set of permission groups that are specified to the policy.

ID string

Identifier of the permission group.

Meta TokenPolicyPermissionGroupsMetaoptional

Attributes associated to the permission group.

Key stringoptional
Value stringoptional
Name stringoptional

Name of the permission group.

Resources TokenPolicyResourcesUnion

A list of resource names that the policy applies to.

One of the following:
type TokenPolicyResourcesIAMResourcesTypeObjectString map[string, string]

Map of simple string resource permissions

type TokenPolicyResourcesIAMResourcesTypeObjectNested map[string, map[string, string]]

Map of nested resource permissions

Status TokenStatusoptional

Status of the token.

One of the following:
const TokenStatusActive TokenStatus = "active"
const TokenStatusDisabled TokenStatus = "disabled"
const TokenStatusExpired TokenStatus = "expired"

List Tokens

package main

import (
  "context"
  "fmt"

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

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  page, err := client.User.Tokens.List(context.TODO(), user.TokenListParams{

  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": [
    {
      "id": "ed17574386854bf78a67040be0a770b0",
      "condition": {
        "request_ip": {
          "in": [
            "123.123.123.0/24",
            "2606:4700::/32"
          ],
          "not_in": [
            "123.123.123.100/24",
            "2606:4700:4700::/48"
          ]
        }
      },
      "expires_on": "2020-01-01T00:00:00Z",
      "issued_on": "2018-07-01T05:20:00Z",
      "last_used_on": "2020-01-02T12:34:00Z",
      "modified_on": "2018-07-02T05:20:00Z",
      "name": "readonly token",
      "not_before": "2018-07-01T05:20:00Z",
      "policies": [
        {
          "id": "f267e341f3dd4697bd3b9f71dd96247f",
          "effect": "allow",
          "permission_groups": [
            {
              "id": "c8fed203ed3043cba015a93ad1616f1f",
              "meta": {
                "key": "key",
                "value": "value"
              },
              "name": "Zone Read"
            },
            {
              "id": "82e64a83756745bbbb1c9c2701bf816b",
              "meta": {
                "key": "key",
                "value": "value"
              },
              "name": "Magic Network Monitoring"
            }
          ],
          "resources": {
            "foo": "string"
          }
        }
      ],
      "status": "active"
    }
  ],
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 2000
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": [
    {
      "id": "ed17574386854bf78a67040be0a770b0",
      "condition": {
        "request_ip": {
          "in": [
            "123.123.123.0/24",
            "2606:4700::/32"
          ],
          "not_in": [
            "123.123.123.100/24",
            "2606:4700:4700::/48"
          ]
        }
      },
      "expires_on": "2020-01-01T00:00:00Z",
      "issued_on": "2018-07-01T05:20:00Z",
      "last_used_on": "2020-01-02T12:34:00Z",
      "modified_on": "2018-07-02T05:20:00Z",
      "name": "readonly token",
      "not_before": "2018-07-01T05:20:00Z",
      "policies": [
        {
          "id": "f267e341f3dd4697bd3b9f71dd96247f",
          "effect": "allow",
          "permission_groups": [
            {
              "id": "c8fed203ed3043cba015a93ad1616f1f",
              "meta": {
                "key": "key",
                "value": "value"
              },
              "name": "Zone Read"
            },
            {
              "id": "82e64a83756745bbbb1c9c2701bf816b",
              "meta": {
                "key": "key",
                "value": "value"
              },
              "name": "Magic Network Monitoring"
            }
          ],
          "resources": {
            "foo": "string"
          }
        }
      ],
      "status": "active"
    }
  ],
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 2000
  }
}