# Update Contact Topics

> PATCH /contacts/:id/topics — update topic subscriptions for a contact.

`PATCH /contacts/:id/topics`

Update topic subscriptions for a contact. The contact is identified in the path by either its ID or its email address.

Either `id` or `email` must be provided.

**Path parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | No | The Contact ID. |
| `email` | string | No | The Contact Email. |

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `topics` | array | Yes | Array of topic subscription updates. Each item has the properties below. |
| `topics[].id` | string | Yes | The Topic ID. |
| `topics[].subscription` | string | Yes | The subscription action. Must be either `opt_in` or `opt_out`. |

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.contacts.updateTopics('e169aa45-1ecf-4183-9955-b1499d5701d3', [
  {
    "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    "subscription": "opt_out"
  }
]);
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Contacts.update_topics("e169aa45-1ecf-4183-9955-b1499d5701d3", [
  {
    "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    "subscription": "opt_out"
  }
])
```

**PHP**

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

$mailblastr->contacts->updateTopics('e169aa45-1ecf-4183-9955-b1499d5701d3', [
  [
    'id' => "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    'subscription' => "opt_out"
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Contacts.update_topics("e169aa45-1ecf-4183-9955-b1499d5701d3", [
  {
    "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    "subscription": "opt_out"
  }
])
```

**Go**

```go
package main

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

func main() {
    req, _ := http.NewRequest("PATCH", "https://api.mailblastr.com/contacts/e169aa45-1ecf-4183-9955-b1499d5701d3/topics", strings.NewReader(`[
  {
    "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    "subscription": "opt_out"
  }
]`))
    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/e169aa45-1ecf-4183-9955-b1499d5701d3/topics")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"[
  {
    "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    "subscription": "opt_out"
  }
]"#)
        .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/e169aa45-1ecf-4183-9955-b1499d5701d3/topics"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("""
[
  {
    "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    "subscription": "opt_out"
  }
]
"""))
    .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/e169aa45-1ecf-4183-9955-b1499d5701d3/topics");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"[
  {
    ""id"": ""b6d24b8e-af0b-4c3c-be0c-359bbd97381e"",
    ""subscription"": ""opt_out""
  }
]", 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/e169aa45-1ecf-4183-9955-b1499d5701d3/topics' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
    "subscription": "opt_out"
  }
]'
```

### Response

```json
{
  "id": "e169aa45-1ecf-4183-9955-b1499d5701d3"
}
```

The `id` in the response is the **contact** id (not a topic id).
