---
title: "Unsubscribe devices from a topic"
description: "Remove devices from one of your app's topics.\n\nIdempotent from the caller's side — unsubscribing a device that was never\nsubscribed succeeds."
---

> Documentation Index
> Fetch the complete documentation index at: https://truememory-docs.mvstg.com/llms.txt
> Use this file to discover all available pages before exploring further.

Path: AI Gateway API › Notifications

`POST /notifications/topics/{topic}/unsubscribe`

Remove devices from one of your app's topics.

Idempotent from the caller's side — unsubscribing a device that was never
subscribed succeeds.

## Authentication

- `HTTPBearer`, http, header `Authorization`

## Path parameters

- `topic` (`unsubscribe_from_topic.path.topic`; string, required) — Topic name, unprefixed.
  - maxLength 900; pattern `^[a-zA-Z0-9\-_.~%]+$`

## Header parameters

- `X-App-Id` (`unsubscribe_from_topic.header.X-App-Id`; any of, optional)
  - any of: `string`, `null`
- `X-On-Behalf-Of` (`unsubscribe_from_topic.header.X-On-Behalf-Of`; any of, optional)
  - any of: `string`, `null`
- `X-External-User-Id` (`unsubscribe_from_topic.header.X-External-User-Id`; any of, optional)
  - any of: `string`, `null`

## Request body

_Required._

- `user_ids` (`unsubscribe_from_topic.user_ids`; any of, optional) — Truememory user ids; resolved to registered devices for the calling app.
  - any of: `array<string>`, `null`
- `tokens` (`unsubscribe_from_topic.tokens`; any of, optional) — Raw FCM registration tokens.
  - any of: `array<string>`, `null`

## Example request

```json
{
  "user_ids": [
    "string"
  ],
  "tokens": [
    "string"
  ]
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://truememory-api.mvstg.com/notifications/topics/<topic>/unsubscribe' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "user_ids": [
    "string"
  ],
  "tokens": [
    "string"
  ]
}
'
```

### TypeScript

```typescript
const url = 'https://truememory-api.mvstg.com/notifications/topics/<topic>/unsubscribe';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({user_ids: ['string'], tokens: ['string']})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://truememory-api.mvstg.com/notifications/topics/<topic>/unsubscribe"

payload = {
    "user_ids": ["string"],
    "tokens": ["string"]
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Successful Response

#### Example

```json
{
  "topic": "string",
  "success_count": 0,
  "failure_count": 0,
  "results": [
    {
      "target": "string",
      "user_id": "string",
      "success": true,
      "message_id": "string",
      "error_code": "string",
      "error": "string",
      "pruned": false
    }
  ],
  "unreachable_user_ids": [
    "string"
  ],
  "pruned_token_count": 0
}
```

- `topic` (`unsubscribe_from_topic.response.200.topic`; string, required) — The app-namespaced topic FCM was given.
- `success_count` (`unsubscribe_from_topic.response.200.success_count`; integer, required)
- `failure_count` (`unsubscribe_from_topic.response.200.failure_count`; integer, required)
- `results` (`unsubscribe_from_topic.response.200.results`; array<object>, required)
  - `target` (`unsubscribe_from_topic.response.200.results.target`; string, required) — The registration token, topic, or condition sent to.
  - `success` (`unsubscribe_from_topic.response.200.results.success`; boolean, required)
  - `user_id` (`unsubscribe_from_topic.response.200.results.user_id`; any of, optional) — Set when the target was resolved from the device registry.
    - any of: `string`, `null`
  - `message_id` (`unsubscribe_from_topic.response.200.results.message_id`; any of, optional)
    - any of: `string`, `null`
  - `error_code` (`unsubscribe_from_topic.response.200.results.error_code`; any of, optional) — FCM's error code, uppercased.
    - any of: `string`, `null`
  - `error` (`unsubscribe_from_topic.response.200.results.error`; any of, optional)
    - any of: `string`, `null`
  - `pruned` (`unsubscribe_from_topic.response.200.results.pruned`; boolean, optional) — The token was dropped from the registry because FCM reports it dead.
    - default `false`
- `unreachable_user_ids` (`unsubscribe_from_topic.response.200.unreachable_user_ids`; array<string>, optional) — Requested users with no device registered for this app.
- `pruned_token_count` (`unsubscribe_from_topic.response.200.pruned_token_count`; integer, optional)
  - default `0`

### 422

Validation Error

#### Example

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}
```

- `detail` (`unsubscribe_from_topic.response.422.detail`; array<object>, optional)
  - `loc` (`unsubscribe_from_topic.response.422.detail.loc`; array<any of>, required)
    - any of: `string`, `integer`
  - `msg` (`unsubscribe_from_topic.response.422.detail.msg`; string, required)
  - `type` (`unsubscribe_from_topic.response.422.detail.type`; string, required)
  - `input` (`unsubscribe_from_topic.response.422.detail.input`; unknown, optional)
  - `ctx` (`unsubscribe_from_topic.response.422.detail.ctx`; object, optional)


Source: https://truememory-docs.mvstg.com/api/notifications/topics/unsubscribe/index.md
