Table of Contents

Interface IMembersApi

Namespace
Cloudflare.NET.Members
Assembly
Cloudflare.NET.dll

Provides access to Cloudflare Account Members API.

Account members are users who have been granted access to an account's resources. This API allows inviting new members, managing their roles, and removing access.

public interface IMembersApi

Examples

// List all members
await foreach (var member in client.Members.ListAllAccountMembersAsync(accountId))
{
  Console.WriteLine($"{member.User.Email} - {member.Status}");
}

// Invite a new member
var request = new CreateAccountMemberRequest(
  Email: "[email protected]",
  Roles: new[] { roleId }
);
var newMember = await client.Members.CreateAccountMemberAsync(accountId, request);

Remarks

When a new member is invited, they receive an email and must accept the invitation to gain access. Members can have multiple roles that define their permissions.

Important: Modifying or removing members may have security implications. Ensure you have proper authorization before making changes.

Methods

CreateAccountMemberAsync(string, CreateAccountMemberRequest, CancellationToken)

Invites a new member to the account.

An invitation email will be sent to the specified email address. The user must accept the invitation to become an active member.

Task<AccountMember> CreateAccountMemberAsync(string accountId, CreateAccountMemberRequest request, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

request CreateAccountMemberRequest

The invitation details including email and roles.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<AccountMember>

The created member (with status "pending" until accepted).

Examples

var request = new CreateAccountMemberRequest(
  Email: "[email protected]",
  Roles: new[] { dnsAdminRoleId }
);
var member = await client.Members.CreateAccountMemberAsync(accountId, request);
Console.WriteLine($"Invited {member.User.Email}, status: {member.Status}");

Remarks

Preview: This operation has limited test coverage.

The email address must not already be associated with an existing member. At least one role must be specified.

Exceptions

ArgumentNullException

Thrown when accountId or request is null.

ArgumentException

Thrown when accountId is empty or whitespace.

DeleteAccountMemberAsync(string, string, CancellationToken)

Removes a member from the account.

The user will immediately lose access to the account's resources. This action cannot be undone - the user must be re-invited to regain access.

Task<DeleteAccountMemberResult> DeleteAccountMemberAsync(string accountId, string memberId, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

memberId string

The membership identifier.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<DeleteAccountMemberResult>

Result containing the deleted membership ID.

Examples

var result = await client.Members.DeleteAccountMemberAsync(accountId, memberId);
Console.WriteLine($"Removed member: {result.Id}");

Remarks

Preview: This operation has limited test coverage.

Warning: You cannot remove yourself from an account. Attempting to do so will result in an error.

Exceptions

ArgumentNullException

Thrown when accountId or memberId is null.

ArgumentException

Thrown when accountId or memberId is empty or whitespace.

HttpRequestException

Thrown when the member is not found (HTTP 404).

GetAccountMemberAsync(string, string, CancellationToken)

Gets details for a specific account member.

Task<AccountMember> GetAccountMemberAsync(string accountId, string memberId, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

memberId string

The membership identifier.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<AccountMember>

The member details including user info and roles.

Examples

var member = await client.Members.GetAccountMemberAsync(accountId, memberId);
Console.WriteLine($"Member: {member.User.Email}");
Console.WriteLine($"Status: {member.Status}");
Console.WriteLine($"Roles: {string.Join(", ", member.Roles.Select(r => r.Name))}");

Exceptions

ArgumentNullException

Thrown when accountId or memberId is null.

ArgumentException

Thrown when accountId or memberId is empty or whitespace.

HttpRequestException

Thrown when the member is not found (HTTP 404).

ListAccountMembersAsync(string, ListAccountMembersFilters?, CancellationToken)

Lists all members of an account.

Returns paginated results of account members with their status and roles.

Task<PagePaginatedResult<AccountMember>> ListAccountMembersAsync(string accountId, ListAccountMembersFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

filters ListAccountMembersFilters

Optional filtering and pagination options.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<PagePaginatedResult<AccountMember>>

A page of account members.

Examples

var members = await client.Members.ListAccountMembersAsync(accountId,
  new ListAccountMembersFilters(Status: MemberStatus.Accepted));

foreach (var member in members.Items)
  Console.WriteLine($"{member.User.Email}: {member.Status}");

Exceptions

ArgumentNullException

Thrown when accountId is null.

ArgumentException

Thrown when accountId is empty or whitespace.

ListAllAccountMembersAsync(string, ListAccountMembersFilters?, CancellationToken)

Lists all members of an account, automatically handling pagination.

IAsyncEnumerable<AccountMember> ListAllAccountMembersAsync(string accountId, ListAccountMembersFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

filters ListAccountMembersFilters

Optional filtering options. Pagination parameters are ignored.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<AccountMember>

An async enumerable of all account members.

Examples

// Iterate through all members without manual pagination
await foreach (var member in client.Members.ListAllAccountMembersAsync(accountId))
{
  Console.WriteLine($"{member.User.Email}: {string.Join(", ", member.Roles.Select(r => r.Name))}");
}

Exceptions

ArgumentNullException

Thrown when accountId is null.

ArgumentException

Thrown when accountId is empty or whitespace.

UpdateAccountMemberAsync(string, string, UpdateAccountMemberRequest, CancellationToken)

Updates an existing account member's roles.

Only the roles assigned to the member can be updated. The user's email and status cannot be changed.

Task<AccountMember> UpdateAccountMemberAsync(string accountId, string memberId, UpdateAccountMemberRequest request, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

memberId string

The membership identifier.

request UpdateAccountMemberRequest

The updated member details.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<AccountMember>

The updated member.

Examples

var request = new UpdateAccountMemberRequest(
  Roles: new[] { viewerRoleId, dnsAdminRoleId }
);
var updated = await client.Members.UpdateAccountMemberAsync(accountId, memberId, request);

Remarks

Preview: This operation has limited test coverage.

Exceptions

ArgumentNullException

Thrown when any parameter is null.

ArgumentException

Thrown when accountId or memberId is empty or whitespace.

HttpRequestException

Thrown when the member is not found (HTTP 404).