# Update contact

> PATCH /contacts/:id — partially update a contact.

`PATCH /contacts/:id`

Partially update a contact, addressed by `id` or `email`. Only the fields you send are changed; omitted fields are left untouched. The contact’s `email` cannot be changed. An id is exact; when addressing by **email**, include a `domain` field in the body to say which of your sending domains the contact lives on.

**Path parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The contact’s `id` *or* its `email` — either value is accepted in this path segment. |

**Body**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `domain` | string | No | The sending domain the contact belongs to. Needed only when addressing by email; an id is exact. |
| `first_name` | string | No | New first name. Send null (or an empty string) to clear it. |
| `last_name` | string | No | New last name. Send null (or an empty string) to clear it. |
| `unsubscribed` | boolean | No | New opt-out state. Set true to unsubscribe, false to re-subscribe. |
| `properties` | object | No | A map of custom property keys and values to merge into the contact (e.g. `{ "department": "Engineering", "score": 10 }`). Incoming keys win; unmentioned keys are preserved. Each key must be a registered contact property and the value must match its declared type (`string` or `number`). |

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.contacts.update({
  id: '479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6',
  "unsubscribed": true
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Contacts.update({
  "id": "479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6",
  "unsubscribed": true
})
```

**PHP**

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

$mailblastr->contacts->update([
  'id' => "479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6",
  'unsubscribed' => true
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Contacts.update({
  "id": "479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6",
  "unsubscribed": True
})
```

**Go**

```go
package main

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

func main() {
    req, _ := http.NewRequest("PATCH", "https://api.mailblastr.com/contacts/479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6", strings.NewReader(`{ "unsubscribed": 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/contacts/479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{ "unsubscribed": 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/contacts/479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("""
{ "unsubscribed": 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/contacts/479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{ ""unsubscribed"": 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/contacts/479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "unsubscribed": true }'
```

**CLI**

```bash
mailblastr contacts update 479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6 \
  --unsubscribed
```

**Response (200)**

```json
{
  "object": "contact",
  "id": "479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6"
}
```

## Audience-scoped variant

The nested route `PATCH /audiences/:audience_id/contacts/:id` still works and scopes the update to one audience (no `domain` field needed):

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.contacts.update({
  audienceId: 'AUDIENCE_ID',
  id: 'steve@example.com',
  "unsubscribed": true
});
console.log({ data, error });
```

**Ruby**

```ruby
require 'net/http'
require 'uri'

uri = URI('https://api.mailblastr.com/audiences/AUDIENCE_ID/contacts/steve@example.com')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Patch.new(uri)
req['Authorization'] = 'Bearer mb_xxxxxxxxx'
req['Content-Type'] = 'application/json'
req.body = <<~JSON
{ "unsubscribed": true }
JSON
res = http.request(req)
puts res.body
```

**PHP**

```php
<?php
$ch = curl_init('https://api.mailblastr.com/audiences/AUDIENCE_ID/contacts/steve@example.com');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer mb_xxxxxxxxx',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => <<<'JSON'
{ "unsubscribed": true }
JSON,
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
```

**Python**

```python
import requests

res = requests.patch(
    "https://api.mailblastr.com/audiences/AUDIENCE_ID/contacts/steve@example.com",
    headers={"Authorization": "Bearer mb_xxxxxxxxx", "Content-Type": "application/json"},
    json={ "unsubscribed": true },
)
print(res.json())
```

**Go**

```go
package main

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

func main() {
    req, _ := http.NewRequest("PATCH", "https://api.mailblastr.com/audiences/AUDIENCE_ID/contacts/steve@example.com", strings.NewReader(`{ "unsubscribed": 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/audiences/AUDIENCE_ID/contacts/steve@example.com")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{ "unsubscribed": 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/audiences/AUDIENCE_ID/contacts/steve@example.com"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("""
{ "unsubscribed": 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/audiences/AUDIENCE_ID/contacts/steve@example.com");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{ ""unsubscribed"": 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/audiences/AUDIENCE_ID/contacts/steve@example.com' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "unsubscribed": true }'
```

An unknown contact (or audience) returns `404 not_found`. See [Errors](https://www.mailblastr.com/docs/api/errors).
