Table of Contents

Class ZoneRulesetsApi

Namespace
Cloudflare.NET.Zones.Rulesets
Assembly
Cloudflare.NET.dll

Implements the API for managing Rulesets at the zone level.

public class ZoneRulesetsApi : ApiResource, IZoneRulesetsApi
Inheritance
ZoneRulesetsApi
Implements
Inherited Members

Constructors

ZoneRulesetsApi(HttpClient, ILoggerFactory)

Implements the API for managing Rulesets at the zone level.

public ZoneRulesetsApi(HttpClient httpClient, ILoggerFactory loggerFactory)

Parameters

httpClient HttpClient
loggerFactory ILoggerFactory

Methods

AddRuleAsync(string, string, CreateRuleRequest, CancellationToken)

Adds a new rule to a specific zone-level ruleset.

public Task<Ruleset> AddRuleAsync(string zoneId, string rulesetId, CreateRuleRequest rule, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

rulesetId string

The ID of the ruleset.

rule CreateRuleRequest

The rule to add.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The updated parent ruleset.

CreateAsync(string, CreateRulesetRequest, CancellationToken)

Creates a new ruleset for a zone.

public Task<Ruleset> CreateAsync(string zoneId, CreateRulesetRequest request, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

request CreateRulesetRequest

The request containing the details of the ruleset to create.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The created ruleset.

DeleteAsync(string, string, CancellationToken)

Deletes a ruleset from a zone.

public Task DeleteAsync(string zoneId, string rulesetId, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

rulesetId string

The ID of the ruleset to delete.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

DeleteRuleAsync(string, string, string, CancellationToken)

Deletes a rule from a zone-level ruleset.

public Task<Ruleset> DeleteRuleAsync(string zoneId, string rulesetId, string ruleId, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

rulesetId string

The ID of the ruleset.

ruleId string

The ID of the rule to delete.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The updated parent ruleset.

GetAsync(string, string, CancellationToken)

Gets a single ruleset by its ID within a zone.

public Task<Ruleset> GetAsync(string zoneId, string rulesetId, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

rulesetId string

The ID of the ruleset to retrieve.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The requested ruleset.

GetPhaseEntrypointAsync(string, string, CancellationToken)

Gets the entrypoint ruleset for a specific phase at the zone level.

public Task<Ruleset> GetPhaseEntrypointAsync(string zoneId, string phase, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

phase string

The phase of the entrypoint (e.g., "http_request_firewall_managed").

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The entrypoint ruleset.

GetPhaseEntrypointVersionAsync(string, string, string, CancellationToken)

Gets a specific version of a phase entrypoint ruleset at the zone level.

public Task<Ruleset> GetPhaseEntrypointVersionAsync(string zoneId, string phase, string version, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

phase string

The phase of the entrypoint.

version string

The version number to retrieve.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The specified version of the ruleset.

ListAllAsync(string, int?, CancellationToken)

Lists all rulesets for a zone, automatically handling cursor-based pagination.

public IAsyncEnumerable<Ruleset> ListAllAsync(string zoneId, int? perPage = null, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

perPage int?

The number of results to fetch per API page.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<Ruleset>

An asynchronous stream of all rulesets for the zone.

Remarks

This method simplifies fetching all rulesets by abstracting away the pagination logic.

ListAsync(string, ListRulesetsFilters?, CancellationToken)

Lists all rulesets for a zone, allowing for manual pagination control.

public Task<CursorPaginatedResult<Ruleset>> ListAsync(string zoneId, ListRulesetsFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

filters ListRulesetsFilters

Optional pagination filters, including the cursor from a previous response.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<CursorPaginatedResult<Ruleset>>

A single page of rulesets along with pagination information.

Remarks

This method is intended for developers who need to control the pagination process manually. To fetch the next page of results, use the Cursor from the CursorInfo property of the returned CursorPaginatedResult<T> in your next call.

ListPhaseEntrypointVersionsAsync(string, string, ListRulesetVersionsFilters?, CancellationToken)

Lists the version history for a specific phase entrypoint at the zone level, allowing for manual pagination.

public Task<PagePaginatedResult<Ruleset>> ListPhaseEntrypointVersionsAsync(string zoneId, string phase, ListRulesetVersionsFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

phase string

The phase of the entrypoint.

filters ListRulesetVersionsFilters

Optional pagination filters.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<PagePaginatedResult<Ruleset>>

A single page of ruleset versions along with pagination information.

UpdateAsync(string, string, UpdateRulesetRequest, CancellationToken)

Updates an existing ruleset in a zone.

public Task<Ruleset> UpdateAsync(string zoneId, string rulesetId, UpdateRulesetRequest request, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

rulesetId string

The ID of the ruleset to update.

request UpdateRulesetRequest

The request containing the fields to update.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The updated ruleset.

UpdatePhaseEntrypointAsync(string, string, IEnumerable<CreateRuleRequest>, CancellationToken)

Updates the entrypoint ruleset for a specific phase at the zone level.

public Task<Ruleset> UpdatePhaseEntrypointAsync(string zoneId, string phase, IEnumerable<CreateRuleRequest> rules, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

phase string

The phase of the entrypoint.

rules IEnumerable<CreateRuleRequest>

The list of rules to set for the ruleset.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The updated ruleset.

UpdateRuleAsync(string, string, string, object, CancellationToken)

Updates an existing rule within a zone-level ruleset.

public Task<Ruleset> UpdateRuleAsync(string zoneId, string rulesetId, string ruleId, object rule, CancellationToken cancellationToken = default)

Parameters

zoneId string

The ID of the zone.

rulesetId string

The ID of the ruleset containing the rule.

ruleId string

The ID of the rule to update.

rule object

The partial rule object with fields to update.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Ruleset>

The updated parent ruleset.