Table of Contents

Class CreateApiTokenRequest

Namespace
Cloudflare.NET.ApiTokens.Models
Assembly
Cloudflare.NET.dll

Request to create a new API token.

public record CreateApiTokenRequest : IEquatable<CreateApiTokenRequest>
Inheritance
CreateApiTokenRequest
Implements
Inherited Members

Examples

var request = new CreateApiTokenRequest(
  Name: "CI/CD Token",
  Policies: new[]
  {
    new CreateTokenPolicyRequest(
      Effect: "allow",
      PermissionGroups: new[] { new TokenPermissionGroupReference("...") },
      Resources: new Dictionary<string, string>
      {
        ["com.cloudflare.api.account.*"] = "*"
      })
  },
  ExpiresOn: DateTime.UtcNow.AddYears(1));

Constructors

CreateApiTokenRequest(string, IReadOnlyList<CreateTokenPolicyRequest>, DateTime?, DateTime?, TokenCondition?)

Request to create a new API token.

public CreateApiTokenRequest(string Name, IReadOnlyList<CreateTokenPolicyRequest> Policies, DateTime? ExpiresOn = null, DateTime? NotBefore = null, TokenCondition? Condition = null)

Parameters

Name string

Human-readable token name.

Policies IReadOnlyList<CreateTokenPolicyRequest>

Token policies defining permissions.

ExpiresOn DateTime?

When the token expires.

NotBefore DateTime?

Token is not valid before this time.

Condition TokenCondition

IP-based access restrictions.

Examples

var request = new CreateApiTokenRequest(
  Name: "CI/CD Token",
  Policies: new[]
  {
    new CreateTokenPolicyRequest(
      Effect: "allow",
      PermissionGroups: new[] { new TokenPermissionGroupReference("...") },
      Resources: new Dictionary<string, string>
      {
        ["com.cloudflare.api.account.*"] = "*"
      })
  },
  ExpiresOn: DateTime.UtcNow.AddYears(1));

Properties

Condition

IP-based access restrictions.

[JsonPropertyName("condition")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public TokenCondition? Condition { get; init; }

Property Value

TokenCondition

ExpiresOn

When the token expires.

[JsonPropertyName("expires_on")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public DateTime? ExpiresOn { get; init; }

Property Value

DateTime?

Name

Human-readable token name.

[JsonPropertyName("name")]
public string Name { get; init; }

Property Value

string

NotBefore

Token is not valid before this time.

[JsonPropertyName("not_before")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public DateTime? NotBefore { get; init; }

Property Value

DateTime?

Policies

Token policies defining permissions.

[JsonPropertyName("policies")]
public IReadOnlyList<CreateTokenPolicyRequest> Policies { get; init; }

Property Value

IReadOnlyList<CreateTokenPolicyRequest>