# 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 { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

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

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

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

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

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

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

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

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

updated, err := client.Contacts.Update(&sendping.UpdateContactRequest{
    Id:           "479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6",
    Unsubscribed: sendping.Bool(true),
})
```

**Rust**

```rust
use sendping::{SendPing, UpdateContactOptions};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = UpdateContactOptions::new("479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6")
    .with_unsubscribed(true);
let _updated = mb.contacts.update(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.UpdateContactRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

UpdateContactRequest request = UpdateContactRequest.builder()
        .id("479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6")
        .unsubscribed(true)
        .build();

SendPingResponse response = sendping.contacts().update(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.ContactUpdateAsync(new ContactUpdateOptions
{
    Id = "479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6",
    Unsubscribed = true,
});
```

**cURL**

```bash
curl -X PATCH 'https://www.sendping.co/api/contacts/479e3145-dd0e-4f64-bf48-1d4b6d4cd8f6' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "unsubscribed": true }'
```

**CLI**

```bash
sendping 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 { SendPing } from 'sendping';

const mb = new SendPing('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://www.sendping.co/api/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
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->contacts->update([
  'audienceId' => "AUDIENCE_ID",
  'id' => "steve@example.com",
  'unsubscribed' => true
]);
```

**Python**

```python
import requests

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

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

updated, err := client.Contacts.Update(&sendping.UpdateContactRequest{
    AudienceId:   "AUDIENCE_ID",
    Id:           "steve@example.com",
    Unsubscribed: sendping.Bool(true),
})
```

**Rust**

```rust
use sendping::{SendPing, UpdateContactOptions};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = UpdateContactOptions::new("steve@example.com")
    .with_audience_id("AUDIENCE_ID")
    .with_unsubscribed(true);
let _updated = mb.contacts.update(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.UpdateContactRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

UpdateContactRequest request = UpdateContactRequest.builder()
        .audienceId("AUDIENCE_ID")
        .id("steve@example.com")
        .unsubscribed(true)
        .build();

SendPingResponse response = sendping.contacts().update(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.ContactUpdateAsync(new ContactUpdateOptions
{
    AudienceId = "AUDIENCE_ID",
    Id = "steve@example.com",
    Unsubscribed = true,
});
```

**cURL**

```bash
curl -X PATCH 'https://www.sendping.co/api/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.sendping.co/docs/api/errors).
