# Update a domain

> PATCH /domains/:id — toggle open and click tracking.

`PATCH /domains/:id`

Updates a domain’s settings. Send any subset of the body fields below; omitted fields are left unchanged. Returns a slim acknowledgement with the domain `id`. Requires a key with full access. See [Open and click tracking](https://www.mailblastr.com/docs/domains/tracking).

**Body**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `open_tracking` | boolean | No | Enable or disable the open-tracking pixel for mail sent from this domain. Applied whenever enabled; the pixel is served from your `tracking_subdomain` when one is configured and verified, otherwise from a shared MailBlastr-hosted host. |
| `click_tracking` | boolean | No | Enable or disable link rewriting for click tracking on this domain. Applied whenever enabled; rewritten links pass through your `tracking_subdomain` when one is configured and verified, otherwise through a shared MailBlastr-hosted host. |
| `tracking_subdomain` | string | No | A custom subdomain for click and open tracking (e.g. `links` produces a CNAME for `links.yourdomain.com`). This value can only be changed after it has first been specified, never removed — this preserves links in already-sent email. After changing it, the new DNS record must be verified; until then the previous value is used, and all previously used records remain active and are included in the response. |
| `tls` | string | No | The domain’s TLS preference. `opportunistic` (default) encrypts the connection when the receiving server supports TLS and otherwise sends unencrypted; `enforced` records a preference that delivery should require TLS. |
| `capabilities` | object | No | Update the domain capabilities. `sending` is always `enabled` and cannot be disabled. Set `receiving` (`enabled` | `disabled`) to toggle whether the domain also receives mail; omitting it keeps the current value. |

**Node.js**

```js
import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.domains.update('d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e', {
  "open_tracking": true,
  "click_tracking": true
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Domains.update("d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e", {
  "open_tracking": true,
  "click_tracking": true
})
```

**PHP**

```php
$mailblastr = Mailblastr::client('mb_xxxxxxxxx');

$mailblastr->domains->update('d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e', [
  'open_tracking' => true,
  'click_tracking' => true
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Domains.update("d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e", {
  "open_tracking": True,
  "click_tracking": True
})
```

**Go**

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    req, _ := http.NewRequest("PATCH", "https://api.mailblastr.com/domains/d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e", strings.NewReader(`{
  "open_tracking": true,
  "click_tracking": true
}`))
    req.Header.Set("Authorization", "Bearer mb_xxxxxxxxx")
    req.Header.Set("Content-Type", "application/json")
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    out, _ := io.ReadAll(res.Body)
    fmt.Println(string(out))
}
```

**Rust**

```rust
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let res = Client::new()
        .patch("https://api.mailblastr.com/domains/d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{
  "open_tracking": true,
  "click_tracking": true
}"#)
        .send()
        .await?;
    println!("{}", res.text().await?);
    Ok(())
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mailblastr.com/domains/d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("""
{
  "open_tracking": true,
  "click_tracking": true
}
"""))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**.NET**

```csharp
using System.Net.Http;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Patch, "https://api.mailblastr.com/domains/d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{
  ""open_tracking"": true,
  ""click_tracking"": true
}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

**cURL**

```bash
curl -X PATCH 'https://api.mailblastr.com/domains/d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "open_tracking": true,
  "click_tracking": true
}'
```

**CLI**

```bash
mailblastr domains update d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e \
  --open-tracking \
  --click-tracking
```

Response:

```json
{
  "object": "domain",
  "id": "d91a7c4e-1f2b-4a8c-9e3d-7b5f0a2c1d6e"
}
```

> **Note:** The response is a slim acknowledgement with only `object` and `id`. To read the updated domain object, follow up with [`GET /domains/:id`](https://www.mailblastr.com/docs/api/domains-get).

Errors: `not_found` if the domain does not exist or is not yours, `invalid_access` if the key lacks full access. See [Errors](https://www.mailblastr.com/docs/api/errors).
