Free and open implementation of the Cloudflare API prtocol v4 in C# .net core, allowing cross-platform automated interaction with Cloudflare.
Install the Nuget package.
Add configuration:
{
"ApiKey": "<your api key here>",
"Username": "[email protected]",
"Endpoint": "https://api.cloudflare.test/client/v4/"
}
Register with dependency injection:
serviceCollection.AddHttpClient();
serviceCollection.AddCloudflareClient(configuration);
private readonly ICloudflareClient cloudflareClient;
public SomeConstructor(ICloudflareClient cloudflareClient) {
this.cloudflareClient = cloudflareClient ?? throw new ArgumentNullException(nameof(cloudflareClient));
}
public void DoSomething() {
var zone = await cloudflareClient.Zones.GetAsync("kenc.dk");
}
Not using dependency injection? See IntegrationTests.cs for an example on how to create a client.
Get a specific Zone
var zone = await cloudflareClient.Zones.GetAsync("kenc.dk");
Add a TXT record to the zone
DNSRecord dnsRecord;
try
{
dnsRecord = await cloudflareClient.ZoneDNSSettingsClient.CreateRecordAsync(zone.Id, "_dummyrecord", DNSRecordType.TXT, "TXT record entry value", 3600);
return dnsRecord.Id;
}
catch (CloudflareException exception) when (exception.Errors[0].Code == "81057")
{
Program.LogLine("The DNS entry already exists.");
return string.Empty;
}
- Request a new feature using GitHub Issues.
- File a bug in GitHub Issues.
- Tweet or Mastodon with any other feedback.
Kenc.AcmeLib Library for interacting with ACME-based certificate providers, incl. LetsEncrypt.
Licensed under the MIT License.