Getting started
Once you've installed the package (see homepage), you will need to retrieve your Challonge! API key, which you can find here.
Caution
This key allows direct interaction with the tournaments your account has access to. Do not share it with anyone else and protect it like you would a password.
Every API interaction happens through the ChallongeClient
. You can either instantiate it normally
or use dependency injection.
Add these using
directives:
using System.Net.Http;
using System.Collections.Generic;
using Challonge.Api;
using Challonge.Objects;
Create the client and use its methods:
class Program
{
private static readonly HttpClient _httpClient = new();
private static readonly ChallongeCredentials _credentials = new("username", "apiKey");
private static readonly ChallongeClient _client = new(_httpClient, _credentials);
static void Main(string[] args)
{
IEnumerable<Tournament> tournaments = _client.GetTournamentsAsync().Result;
}
}
Example
Assume we have an already-configured ChallongeClient
_client
as a field in our class.
public async Task<Tournament> Example()
{
TournamentInfo info = new()
{
AcceptAttachments = true,
TournamentType = TournamentType.DoubleElimination,
Name = "SSBM Weekly #46"
};
Tournament tournament = await _client.CreateTournamentAsync(info);
for (int i = 1; i <= 5; i++)
{
ParticipantInfo pInfo = new()
{
Name = $"player{i}"
};
await _client.CreateParticipantAsync(tournament, pInfo);
}
IEnumerable<Participant> participants = await _client.RandomizeParticipantsAsync(tournament);
foreach (Participant p in participants)
{
ParticipantInfo pInfo = new()
{
Misc = p.Seed % 2 == 0 ? "Even seed" : "Odd seed";
};
await _client.UpdateParticipantAsync(p, pInfo);
}
tournament = await _client.GetTournamentByIdAsync(tournament.Id);
return tournament;
}
Caution
Remember that your api key is very sensitive. In the previous example, we copy-pasted the api key and Challonge! username into the code, which is NOT secure, especially if you plan on distributing the application in any shape or form.
We recommend alternative storage such as environment variables, an external configuration file, or a secrets manager for safe handling.