---
title: "client.DnsConnections"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/csharp/reference/dns-connections"
area: "C#"
category: "Reference"
---

# client.DnsConnections

Every method in this namespace: its signature, its parameters, what it returns and an example.

## Methods

The DNS provider accounts connected to the workspace, through which OpenEmail writes the records of a domain itself: list them, read what disconnecting one would leave behind, and disconnect it. Connecting one is done in the app, because the provider asks the person to sign in.

### `DnsConnections.ListAsync`

List the DNS provider accounts connected to the workspace

```csharp
Task<JsonObject> ListAsync(string? apiKey = null, CancellationToken cancellationToken = default)
```

Returns every DNS provider account connected to the workspace, through which OpenEmail writes the records of a domain itself, as the Providers tab of the domains page in the app shows them. Each one names the domains it serves, how many records OpenEmail wrote through it and still keeps, and whether it is `active`, needs connecting again (`needs-reauth`) or was disconnected (`revoked`).

`configured` is false when this server cannot connect a provider at all. A connection is made in the app, because the provider asks the person to sign in, so there is no method to create one.

Scopes: `domains:read`.

**Parameters**

- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` with `configured` and every connection in `data`, a list of objects, disconnected ones included.

**Example**

```csharp
var connections = await client.DnsConnections.ListAsync();

foreach (var connection in connections["data"]?.AsArray() ?? [])
{
    Console.WriteLine($"{connection?["subject"]} {connection?["status"]} {connection?["domains"]?.AsArray().Count} domains");
}
```

**Notes**

- A GET is retried automatically on network failure and on 408, 429, 500, 502, 503 and 504 responses, up to the client's `MaxRetries`.

Also available in: API [`GET /dns-connections`](https://openemail.uk/docs/api/reference/domains#get-dns-connections); TypeScript [`dnsConnections.list()`](https://openemail.uk/docs/sdk/reference/dns-connections#list); Python [`dns_connections.list()`](https://openemail.uk/docs/python/reference/dns-connections#list); Ruby [`dns_connections.list`](https://openemail.uk/docs/ruby/reference/dns-connections#list); PHP [`dnsConnections->list`](https://openemail.uk/docs/php/reference/dns-connections#list); Go [`DNSConnections.List`](https://openemail.uk/docs/go/reference/dns-connections#list); Java [`dnsConnections().list`](https://openemail.uk/docs/java/reference/dns-connections#list); CLI [`openemail dns-connections list`](https://openemail.uk/docs/cli/reference/dns-connections#dns-connections-list).

### `DnsConnections.GetAsync`

Read a DNS connection and what disconnecting it would leave behind

```csharp
Task<JsonObject> GetAsync(
    string id,
    string? apiKey = null,
    CancellationToken cancellationToken = default)
```

Returns one connection with what disconnecting it would do: the domains it serves, the records OpenEmail wrote through it, `busy` for the domains a sync is running on right now, which hold a disconnect back until it ends, and `keepsMail` for the verified domains that stop receiving mail once their records come down.

Scopes: `domains:read`.

**Parameters**

- `id` (`string`, required): A connection id from `DnsConnections.ListAsync`.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` with the fields of a connection in `DnsConnections.ListAsync`, plus `busy` and `keepsMail`, each a list of domain names.

**Example**

```csharp
var connection = await client.DnsConnections.GetAsync("dnsl_3f9a1c2e7b4d4e6f8a0b2c3d");

if ((connection["keepsMail"]?.AsArray().Count ?? 0) > 0)
{
    Console.WriteLine($"These stop receiving mail: {string.Join(", ", connection["keepsMail"]?.AsArray() ?? [])}");
}

if ((connection["busy"]?.AsArray().Count ?? 0) > 0)
{
    Console.WriteLine($"Wait for the sync on: {string.Join(", ", connection["busy"]?.AsArray() ?? [])}");
}
```

**Notes**

- A connection id that is not in this workspace is a 404 `resource_not_found`.
- A GET is retried automatically on network failure and on 408, 429, 500, 502, 503 and 504 responses, up to the client's `MaxRetries`.

Also available in: API [`GET /dns-connections/{id}`](https://openemail.uk/docs/api/reference/domains#get-dns-connections-id); TypeScript [`dnsConnections.get()`](https://openemail.uk/docs/sdk/reference/dns-connections#get); Python [`dns_connections.get()`](https://openemail.uk/docs/python/reference/dns-connections#get); Ruby [`dns_connections.get`](https://openemail.uk/docs/ruby/reference/dns-connections#get); PHP [`dnsConnections->get`](https://openemail.uk/docs/php/reference/dns-connections#get); Go [`DNSConnections.Get`](https://openemail.uk/docs/go/reference/dns-connections#get); Java [`dnsConnections().get`](https://openemail.uk/docs/java/reference/dns-connections#get); CLI [`openemail dns-connections get`](https://openemail.uk/docs/cli/reference/dns-connections#dns-connections-get).

### `DnsConnections.DeleteAsync`

Disconnect a DNS provider account

```csharp
Task<JsonObject> DeleteAsync(
    string id,
    string? apiKey = null,
    CancellationToken cancellationToken = default)
```

Disconnects the account as Disconnect does in the app: the records OpenEmail wrote through it come down, every domain it serves is detached, and the connection is revoked at the provider. A verified domain whose records come down stops receiving mail, so read `DnsConnections.GetAsync` first. `detached` counts what came down and lists the records still published, to delete by hand.

A connection that is already disconnected is removed from the list instead, once no domain and no record is left on it, and `removed` says so.

Scopes: `domains:write`.

**Parameters**

- `id` (`string`, required): A connection id from `DnsConnections.ListAsync`.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` for the connection with `removed`, `confirmed` and `detached`.

**Example**

```csharp
try
{
    var result = await client.DnsConnections.DeleteAsync("dnsl_3f9a1c2e7b4d4e6f8a0b2c3d");

    if ((bool?)result["removed"] == true)
    {
        Console.WriteLine("Removed from the list");
    }
    else
    {
        Console.WriteLine($"{result["detached"]?["detached"]?.ToString() ?? "0"} domains detached");
    }
}
catch (OpenEmailApiException error) when (error.IsConflict)
{
    Console.WriteLine($"Not yet: {error.Code}");
}
```

**Notes**

- A sync running on one of its domains is refused with 409 `dns_busy`, and nothing is revoked. A disconnected connection that still has domains or records on it is refused with 409 `dns_connection_in_use`.
- A key or an access token limited to particular addresses or domains is refused with 422 `capability_unsupported`. An access token acting for a member also needs `workspace:manage` in their role, or it is refused with 403 `insufficient_authority`.
- An OAuth access token needs a verification code for this call, and is refused with 403 `step_up_required` until the app has verified one in the last 60 minutes. `IsStepUpRequired` on the error says so. An API key is never asked for a code.
- Not retried by the SDK.

Also available in: API [`DELETE /dns-connections/{id}`](https://openemail.uk/docs/api/reference/domains#delete-dns-connections-id); TypeScript [`dnsConnections.delete()`](https://openemail.uk/docs/sdk/reference/dns-connections#delete); Python [`dns_connections.delete()`](https://openemail.uk/docs/python/reference/dns-connections#delete); Ruby [`dns_connections.delete`](https://openemail.uk/docs/ruby/reference/dns-connections#delete); PHP [`dnsConnections->delete`](https://openemail.uk/docs/php/reference/dns-connections#delete); Go [`DNSConnections.Delete`](https://openemail.uk/docs/go/reference/dns-connections#delete); Java [`dnsConnections().delete`](https://openemail.uk/docs/java/reference/dns-connections#delete); CLI [`openemail dns-connections delete`](https://openemail.uk/docs/cli/reference/dns-connections#dns-connections-delete).
