Class MembersApi
- Namespace
- Cloudflare.NET.Members
- Assembly
- Cloudflare.NET.dll
Implementation of IMembersApi for Cloudflare Account Members.
Provides CRUD operations for managing account members, including inviting new users, updating roles, and removing access.
public class MembersApi : ApiResource, IMembersApi
- Inheritance
-
MembersApi
- Implements
- Inherited Members
Constructors
MembersApi(HttpClient, ILoggerFactory)
Initializes a new instance of the MembersApi class.
public MembersApi(HttpClient httpClient, ILoggerFactory loggerFactory)
Parameters
httpClientHttpClientThe HttpClient for making requests.
loggerFactoryILoggerFactoryThe factory to create loggers for this resource.
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.
public Task<AccountMember> CreateAccountMemberAsync(string accountId, CreateAccountMemberRequest request, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
requestCreateAccountMemberRequestThe invitation details including email and roles.
cancellationTokenCancellationTokenA 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
accountIdorrequestis null.- ArgumentException
Thrown when
accountIdis 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.
public Task<DeleteAccountMemberResult> DeleteAccountMemberAsync(string accountId, string memberId, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
memberIdstringThe membership identifier.
cancellationTokenCancellationTokenA 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
accountIdormemberIdis null.- ArgumentException
Thrown when
accountIdormemberIdis empty or whitespace.- HttpRequestException
Thrown when the member is not found (HTTP 404).
GetAccountMemberAsync(string, string, CancellationToken)
Gets details for a specific account member.
public Task<AccountMember> GetAccountMemberAsync(string accountId, string memberId, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
memberIdstringThe membership identifier.
cancellationTokenCancellationTokenA 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
accountIdormemberIdis null.- ArgumentException
Thrown when
accountIdormemberIdis 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.
public Task<PagePaginatedResult<AccountMember>> ListAccountMembersAsync(string accountId, ListAccountMembersFilters? filters = null, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
filtersListAccountMembersFiltersOptional filtering and pagination options.
cancellationTokenCancellationTokenA 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
accountIdis null.- ArgumentException
Thrown when
accountIdis empty or whitespace.
ListAllAccountMembersAsync(string, ListAccountMembersFilters?, CancellationToken)
Lists all members of an account, automatically handling pagination.
public IAsyncEnumerable<AccountMember> ListAllAccountMembersAsync(string accountId, ListAccountMembersFilters? filters = null, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
filtersListAccountMembersFiltersOptional filtering options. Pagination parameters are ignored.
cancellationTokenCancellationTokenA 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
accountIdis null.- ArgumentException
Thrown when
accountIdis 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.
public Task<AccountMember> UpdateAccountMemberAsync(string accountId, string memberId, UpdateAccountMemberRequest request, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
memberIdstringThe membership identifier.
requestUpdateAccountMemberRequestThe updated member details.
cancellationTokenCancellationTokenA 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
accountIdormemberIdis empty or whitespace.- HttpRequestException
Thrown when the member is not found (HTTP 404).