# 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. You can also send a bare JSON array as the body instead of wrapping it in `{ topics: [...] }` — the example below does exactly that. |
| `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 { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

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

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

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

**PHP**

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

use SendPing\SendPing;

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

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

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

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

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

contact, err := client.Contacts.UpdateTopics("e169aa45-1ecf-4183-9955-b1499d5701d3", &sendping.UpdateContactTopicsRequest{
    Topics: []sendping.TopicSubscriptionUpdate{
        {
            Id:           "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
            Subscription: "opt_out",
        },
    },
})
```

**Rust**

```rust
use sendping::{SendPing, SubscriptionState, UpdateContactTopicsOptions};

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

let params = UpdateContactTopicsOptions::new()
    .with_topic("b6d24b8e-af0b-4c3c-be0c-359bbd97381e", SubscriptionState::OptOut);
let _contact = mb.contacts.update_topics("e169aa45-1ecf-4183-9955-b1499d5701d3", params).await?;
```

**Java**

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

SendPing sendping = new SendPing("mb_xxxxxxxxx");

UpdateContactTopicsRequest request = UpdateContactTopicsRequest.builder()
        .topic("b6d24b8e-af0b-4c3c-be0c-359bbd97381e", "opt_out")
        .build();

SendPingResponse response = sendping.contacts().updateTopics(
        "e169aa45-1ecf-4183-9955-b1499d5701d3",
        request);
```

**.NET**

```csharp
using SendPing;

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

var resp = await sendping.ContactUpdateTopicsAsync("e169aa45-1ecf-4183-9955-b1499d5701d3", new ContactTopicsUpdateOptions
{
    Topics = new List<ContactTopicSetting>
    {
        new()
        {
            Id = "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
            Subscription = "opt_out",
        },
    },
});
```

**cURL**

```bash
curl -X PATCH 'https://www.sendping.co/api/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"
  }
]'
```

**CLI**

```bash
sendping contacts set-topics e169aa45-1ecf-4183-9955-b1499d5701d3 \
  --topics '[{"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).
