# Update campaign

> PATCH /campaigns/:id — edit a draft campaign.

`PATCH /campaigns/:id`

Partially updates a campaign. Only a **draft** can be edited — once it is sending, scheduled, or sent, this returns a `validation_error`. Send only the fields you want to change.

**Path parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The ID of the campaign you want to update. |

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `domain` | string | No | Re-point the campaign at another sending domain’s contacts (draft only). Must be one of your domains. Changing the domain automatically clears `segment_id` and `topic_id` unless new values are provided in the same request. Passing `audience_id` is no longer accepted. |
| `from` | string | No | Sender address on a verified domain. |
| `subject` | string | No | Subject line. |
| `reply_to` | string | string[] | No | Reply-To address. For multiple addresses, send an array of strings. |
| `html` | string | No | HTML body. |
| `text` | string | No | Plain-text body. If omitted, a plain-text version is generated from the HTML; set it to an empty string to opt out. |
| `name` | string | No | The friendly name of the campaign. Only used for internal reference. |
| `preview_text` | string | null | No | Inbox preview text shown after the subject line (max **150 characters**; supports merge tags). Pass `null` to clear. |
| `segment_id` | string | null | No | Re-target a segment. Pass `null` to remove the segment filter. The segment must belong to the same domain. |
| `topic_id` | string | null | No | Re-target a topic gate. Pass `null` to remove it. |

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.campaigns.update('8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90', { "subject": "Updated subject" });
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Campaigns.update("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90", {
  "subject": "Updated subject"
})
```

**PHP**

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

$mailblastr->campaigns->update('8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90', [
  'subject' => "Updated subject"
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Campaigns.update("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90", {
  "subject": "Updated subject"
})
```

**Go**

```go
package main

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

func main() {
    req, _ := http.NewRequest("PATCH", "https://api.mailblastr.com/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90", strings.NewReader(`{ "subject": "Updated subject" }`))
    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/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{ "subject": "Updated subject" }"#)
        .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/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("""
{ "subject": "Updated subject" }
"""))
    .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/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{ ""subject"": ""Updated subject"" }", 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/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "subject": "Updated subject" }'
```

**CLI**

```bash
mailblastr campaigns update 8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90 \
  --subject 'Updated subject'
```

### Response

```json
{
  "id": "8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90"
}
```

> **Note:** Errors: `not_found` if the campaign is not yours; `validation_error` if it is not a draft, `domain` does not reference one of your domains, or `audience_id` is passed (no longer accepted).
