# Class ApiClient | EchoHub Documentation

# Class ApiClient

Namespace
  EchoHub.Client.Services

Assembly
  EchoHub.Client.dll

    public sealed class ApiClient : IDisposable

Inheritance
  object
  ApiClient

Implements
  IDisposable

Inherited Members
  object.GetType()
  object.ToString()
  object.Equals(object)
  object.Equals(object, object)
  object.ReferenceEquals(object, object)
  object.GetHashCode()

## Constructors

### ApiClient(string)

    public ApiClient(string baseUrl)

#### Parameters

`baseUrl` string

## Properties

### BaseUrl

    public string BaseUrl { get; }

#### Property Value

string

### RefreshToken

    public string? RefreshToken { get; }

#### Property Value

string

### Token

    public string? Token { get; }

#### Property Value

string

## Methods

### AssignRoleAsync(string, ServerRole)

    public Task AssignRoleAsync(string username, ServerRole role)

#### Parameters

`username` string
`role` ServerRole

#### Returns

Task

### BanUserAsync(string, string?)

    public Task BanUserAsync(string username, string? reason = null)

#### Parameters

`username` string
`reason` string

#### Returns

Task

### CreateChannelAsync(string, string?, bool, string?, string?, string?)

    public Task<ChannelDto?> CreateChannelAsync(string name, string? topic = null, bool isPublic = true, string? password = null, string? encryptionSalt = null, string? wrappedRoomKey = null)

#### Parameters

`name` string
`topic` string
`isPublic` bool
`password` string
`encryptionSalt` string
`wrappedRoomKey` string

#### Returns

Task<ChannelDto>

### CreateInviteAsync(int?, int?)

    public Task<InviteDto?> CreateInviteAsync(int? maxUses = null, int? expiresInHours = null)

#### Parameters

`maxUses` int?
`expiresInHours` int?

#### Returns

Task<InviteDto>

### DeleteChannelAsync(string)

    public Task DeleteChannelAsync(string channelName)

#### Parameters

`channelName` string

#### Returns

Task

### DeleteMessageAsync(Guid)

    public Task DeleteMessageAsync(Guid messageId)

#### Parameters

`messageId` Guid

#### Returns

Task

### DeleteMyAccountAsync(string)

Deletes the caller's account. The password re-confirms intent.

    public Task DeleteMyAccountAsync(string password)

#### Parameters

`password` string

#### Returns

Task

### Dispose()

    public void Dispose()

### DownloadFileToTempAsync(string, string)

    public Task<string> DownloadFileToTempAsync(string relativeUrl, string fileName)

#### Parameters

`relativeUrl` string
`fileName` string

#### Returns

Task<string>

### ExportMyDataAsync()

Downloads the caller's full data export as raw JSON text.

    public Task<string> ExportMyDataAsync()

#### Returns

Task<string>

### GetChannelCryptoAsync(string)

Fetches a channel's public crypto metadata (whether it's E2E-encrypted and its key-derivation salt). Returns null when the channel doesn't exist.

    public Task<ChannelCryptoDto?> GetChannelCryptoAsync(string channelName)

#### Parameters

`channelName` string

#### Returns

Task<ChannelCryptoDto>

### GetChannelMetaAsync(string)

Fetches a channel's human-facing metadata (message count, unique posters, estimated size, created date, room id) for the `/meta` command. Returns null if it doesn't exist.

    public Task<ChannelMetaDto?> GetChannelMetaAsync(string channelName)

#### Parameters

`channelName` string

#### Returns

Task<ChannelMetaDto>

### GetChannelsAsync()

    public Task<List<ChannelDto>> GetChannelsAsync()

#### Returns

Task<List<ChannelDto>>

### GetEncryptionKeyAsync()

    public Task<string> GetEncryptionKeyAsync()

#### Returns

Task<string>

### GetInvitesAsync()

    public Task<List<InviteDto>> GetInvitesAsync()

#### Returns

Task<List<InviteDto>>

### GetServerInfoAsync()

    public Task<ServerStatusDto?> GetServerInfoAsync()

#### Returns

Task<ServerStatusDto>

### GetUserProfileAsync(string)

    public Task<UserProfileDto?> GetUserProfileAsync(string username)

#### Parameters

`username` string

#### Returns

Task<UserProfileDto>

### GetValidTokenAsync()

Returns a valid access token, refreshing if expired. Used by EchoHubConnection for SignalR token provider.

    public Task<string?> GetValidTokenAsync()

#### Returns

Task<string>

### KickUserAsync(string, string?)

    public Task KickUserAsync(string username, string? reason = null)

#### Parameters

`username` string
`reason` string

#### Returns

Task

### LoginAsync(string, string)

    public Task<LoginResponse> LoginAsync(string username, string password)

#### Parameters

`username` string
`password` string

#### Returns

Task<LoginResponse>

### LoginWithRefreshTokenAsync(string)

    public Task<LoginResponse> LoginWithRefreshTokenAsync(string refreshToken)

#### Parameters

`refreshToken` string

#### Returns

Task<LoginResponse>

### LogoutAsync()

    public Task LogoutAsync()

#### Returns

Task

### MuteUserAsync(string, int?, string?)

    public Task MuteUserAsync(string username, int? durationMinutes = null, string? reason = null)

#### Parameters

`username` string
`durationMinutes` int?
`reason` string

#### Returns

Task

### NukeChannelAsync(string)

    public Task NukeChannelAsync(string channelName)

#### Parameters

`channelName` string

#### Returns

Task

### RefreshTokenAsync()

    public Task RefreshTokenAsync()

#### Returns

Task

### RegisterAsync(string, string, string?, string?)

    public Task<LoginResponse> RegisterAsync(string username, string password, string? displayName = null, string? inviteCode = null)

#### Parameters

`username` string
`password` string
`displayName` string
`inviteCode` string

#### Returns

Task<LoginResponse>

### RekeyChannelAsync(string, RekeyChannelRequest)

    public Task<ChannelDto?> RekeyChannelAsync(string channelName, RekeyChannelRequest request)

#### Parameters

`channelName` string
`request` RekeyChannelRequest

#### Returns

Task<ChannelDto>

### RevokeInviteAsync(string)

    public Task RevokeInviteAsync(string code)

#### Parameters

`code` string

#### Returns

Task

### SendMessageWithAttachmentsAsync(string, string, IReadOnlyList<OutgoingAttachment>, string?)

Sends one message with optional text and one or more file attachments. For end-to-end encrypted channels each attachment carries a declared kind and a room-encrypted preview (empty when none); the caption is likewise room-encrypted.

    public Task<MessageDto?> SendMessageWithAttachmentsAsync(string channelName, string content, IReadOnlyList<OutgoingAttachment> attachments, string? size = null)

#### Parameters

`channelName` string
`content` string
`attachments` IReadOnlyList<OutgoingAttachment>
`size` string

#### Returns

Task<MessageDto>

### SendUrlAsync(string, string, string?)

    public Task<MessageDto?> SendUrlAsync(string channelName, string url, string? size = null)

#### Parameters

`channelName` string
`url` string
`size` string

#### Returns

Task<MessageDto>

### UnbanUserAsync(string)

    public Task UnbanUserAsync(string username)

#### Parameters

`username` string

#### Returns

Task

### UnmuteUserAsync(string)

    public Task UnmuteUserAsync(string username)

#### Parameters

`username` string

#### Returns

Task

### UpdateChannelTopicAsync(string, string?)

    public Task<ChannelDto?> UpdateChannelTopicAsync(string channelName, string? topic)

#### Parameters

`channelName` string
`topic` string

#### Returns

Task<ChannelDto>

### UpdateProfileAsync(UpdateProfileRequest)

    public Task<UserProfileDto?> UpdateProfileAsync(UpdateProfileRequest request)

#### Parameters

`request` UpdateProfileRequest

#### Returns

Task<UserProfileDto>

### UploadAvatarAsync(Stream, string)

    public Task<string?> UploadAvatarAsync(Stream imageStream, string fileName)

#### Parameters

`imageStream` Stream
`fileName` string

#### Returns

Task<string>

## Events

### OnTokensRefreshed

    public event Action? OnTokensRefreshed

#### Event Type

Action