---
source_url: https://www.pubnub.com/docs/sdks/go/api-reference/mobile-push
title: Mobile Push Notifications API for Go SDK
updated_at: 2026-06-05T11:12:08.074Z
sdk_name: PubNub Go SDK
sdk_version: 8.2.0
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Mobile Push Notifications API for Go SDK

PubNub Go SDK, use the latest version: 8.2.0

Install:

```bash
go get github.com/pubnub/go/v8@8.2.0
```

The Mobile Push Notifications feature connects native PubNub publishing to third-party push services. Supported services include Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

To learn more, read about [Mobile Push Notifications](https://www.pubnub.com/docs/general/push/send).

## Add a device to a push notifications channel

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Enable mobile push notifications on a set of channels.

### Method(s)

```go
pn.AddPushNotificationsOnChannels().
        Channels([]string).
        DeviceIDForPush(string).
        PushType(PNPushTypeFCM|PNPushTypeAPNS2).
        Topic(string).
        Environment(PNPushEnvironment).
        QueryParam(map[string]string).
        Execute()
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| Channels | []string | Yes |  | Channels to enable for push notifications. |
| DeviceIDForPush | string | Yes |  | Device ID (push token). |
| PushType | PNPushTypeAPNS2PNPushTypeFCM | Yes | `Not set` | Accepted values: `PNPushTypeAPNS2`, `PNPushTypeFCM`. |
| Topic | string | Optional | `Not set` | APNs topic (bundle identifier). |
| Environment | PNPushEnvironment | Optional | `PNPushEnvironmentDevelopment` | APNs environment. Accepted values: `PNPushEnvironmentDevelopment`, `PNPushEnvironmentProduction`. |
| QueryParam | map[string]string | Optional |  | Map of query parameters to append to the API request. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

#### Add device to channel (FCM)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_addChannelsToPushFCM demonstrates registering a device for FCM push notifications
func Example_addChannelsToPushFCM() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// Add channels to push notifications for FCM (Firebase Cloud Messaging)
	_, status, err := pn.AddPushNotificationsOnChannels().
		Channels([]string{"notifications-channel", "alerts-channel"}). // Channels to enable for push
		DeviceIDForPush("device-fcm-token").                           // FCM device token
		PushType(pubnub.PNPushTypeFCM).                                // Use FCM push type
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("FCM push notifications enabled for channels")
	}

	// Output:
	// FCM push notifications enabled for channels
}
```

#### Add device to channel (APNs2)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_addChannelsToPushAPNS2 demonstrates registering a device for APNs2 push notifications
func Example_addChannelsToPushAPNS2() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// Add channels to push notifications for APNs2 (Apple Push Notification service)
	_, status, err := pn.AddPushNotificationsOnChannels().
		Channels([]string{"notifications-channel", "alerts-channel"}).                       // Channels to enable for push
		DeviceIDForPush("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"). // APNs device token (64 hex chars)
		PushType(pubnub.PNPushTypeAPNS2).                                                    // Use APNs2 push type
		Topic("com.example.myapp").                                                          // APNs topic (bundle identifier)
		Environment(pubnub.PNPushEnvironmentDevelopment).                                    // APNs environment (development or production)
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("APNs2 push notifications enabled for channels")
	}

	// Output:
	// APNs2 push notifications enabled for channels
}
```

### Returns

No payload is returned. Check `status.Error` on the status object.

## List push notifications channels for a device

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Get all channels with push notifications for the specified push token.

### Method(s)

```go
pn.ListPushProvisions().
        DeviceIDForPush(string).
        PushType(PNPushTypeFCM|PNPushTypeAPNS2).
        Topic(string).
        Environment(PNPushEnvironment).
        QueryParam(map[string]string).
        Execute()
```

| Parameter | Description |
| --- | --- |
| `DeviceIDForPush` *Type: stringDefault: n/a | Device ID (push token). |
| `PushType` *Type: PNPushTypeAPNS2 PNPushTypeFCMDefault: `Not set` | Accepted values: `PNPushTypeAPNS2`, `PNPushTypeFCM`. |
| `Topic`Type: stringDefault: `Not set` | APNs topic (bundle identifier). |
| `Environment`Type: PNPushEnvironmentDefault: `PNPushEnvironmentDevelopment` | APNs environment. Accepted values: `PNPushEnvironmentDevelopment`, `PNPushEnvironmentProduction`. |
| `QueryParam`Type: map[string]stringDefault: n/a | Map of query parameters to append to the API request. |

### Sample code

#### List channels for device (FCM)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_listPushChannelsFCM demonstrates listing channels with push enabled for an FCM device
func Example_listPushChannelsFCM() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// Setup: Register some channels first
	pn.AddPushNotificationsOnChannels().
		Channels([]string{"notifications-channel", "alerts-channel"}).
		DeviceIDForPush("device-fcm-token").
		PushType(pubnub.PNPushTypeFCM).
		Execute()

	// List all channels that have push notifications enabled for this FCM device
	response, status, err := pn.ListPushProvisions().
		DeviceIDForPush("device-fcm-token"). // FCM device token
		PushType(pubnub.PNPushTypeFCM).      // Use FCM push type
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		// Display the channels with push enabled
		if len(response.Channels) > 0 {
			fmt.Printf("Push enabled on %d channels\n", len(response.Channels))
		} else {
			fmt.Println("No channels with push enabled")
		}
	}

	// Output:
	// Push enabled on 2 channels
}
```

#### List channels for device (APNs2)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_listPushChannelsAPNS2 demonstrates listing channels with push enabled for an APNs2 device
func Example_listPushChannelsAPNS2() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// List all channels that have push notifications enabled for this APNs2 device
	response, status, err := pn.ListPushProvisions().
		DeviceIDForPush("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"). // APNs device token (64 hex chars)
		PushType(pubnub.PNPushTypeAPNS2).                                                    // Use APNs2 push type
		Topic("com.example.myapp").                                                          // APNs topic (bundle identifier)
		Environment(pubnub.PNPushEnvironmentDevelopment).                                    // APNs environment
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		// Display the channels with push enabled
		if len(response.Channels) > 0 {
			fmt.Printf("Push enabled on %d channels\n", len(response.Channels))
		} else {
			fmt.Println("No channels with push enabled")
		}
	}
}
```

### Returns

Returns `ListPushProvisionsRequestResponse` with:

| Method | Description |
| --- | --- |
| `Channels`Type: []string | Channels associated with push notifications. |

## Remove a device from push notifications channels

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable push notifications on selected channels.

### Method(s)

```go
pn.RemovePushNotificationsFromChannels().
        Channels([]string).
        DeviceIDForPush(string).
        PushType(PNPushTypeFCM|PNPushTypeAPNS2).
        Topic(string).
        Environment(PNPushEnvironment).
        QueryParam(map[string]string).
        Execute()
```

| Parameter | Description |
| --- | --- |
| `Channels` *Type: []stringDefault: n/a | Channels to disable for push notifications. |
| `DeviceIDForPush` *Type: stringDefault: n/a | Device ID (push token). |
| `PushType` *Type: PNPushTypeAPNS2 PNPushTypeFCMDefault: `Not set` | Accepted values: `PNPushTypeAPNS2`, `PNPushTypeFCM`. |
| `Topic`Type: stringDefault: `Not set` | APNs topic (bundle identifier). |
| `Environment`Type: PNPushEnvironmentDefault: `PNPushEnvironmentDevelopment` | APNs environment. Accepted values: `PNPushEnvironmentDevelopment`, `PNPushEnvironmentProduction`. |
| `QueryParam`Type: map[string]stringDefault: n/a | Map of query parameters to append to the API request. |

### Sample code

#### Remove device from channel (FCM)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_removeChannelsFromPushFCM demonstrates removing specific channels from FCM push notifications
func Example_removeChannelsFromPushFCM() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// Remove specific channels from FCM push notifications
	_, status, err := pn.RemovePushNotificationsFromChannels().
		Channels([]string{"alerts-channel"}). // Channels to remove from push
		DeviceIDForPush("device-fcm-token").  // FCM device token
		PushType(pubnub.PNPushTypeFCM).       // Use FCM push type
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("Channels removed from FCM push notifications")
	}

	// Output:
	// Channels removed from FCM push notifications
}
```

#### Remove device from channel (APNs2)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_removeChannelsFromPushAPNS2 demonstrates removing specific channels from APNs2 push notifications
func Example_removeChannelsFromPushAPNS2() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// Remove specific channels from APNs2 push notifications
	_, status, err := pn.RemovePushNotificationsFromChannels().
		Channels([]string{"alerts-channel"}).                                                // Channels to remove from push
		DeviceIDForPush("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"). // APNs device token (64 hex chars)
		PushType(pubnub.PNPushTypeAPNS2).                                                    // Use APNs2 push type
		Topic("com.example.myapp").                                                          // APNs topic (bundle identifier)
		Environment(pubnub.PNPushEnvironmentDevelopment).                                    // APNs environment
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("Channels removed from APNs2 push notifications")
	}

	// Output:
	// Channels removed from APNs2 push notifications
}
```

### Returns

No payload is returned. Check `status.Error` on the status object.

## Remove a device from all push notifications channels

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable push notifications from all channels registered for the specified push token.

### Method(s)

```go
pn.RemoveAllPushNotifications().
        DeviceIDForPush(string).
        PushType(PNPushTypeFCM|PNPushTypeAPNS2).
        Topic(string).
        Environment(PNPushEnvironment).
        QueryParam(map[string]string).
        Execute()
```

| Parameter | Description |
| --- | --- |
| `DeviceIDForPush` *Type: stringDefault: n/a | Device ID (push token). |
| `PushType` *Type: PNPushTypeAPNS2 PNPushTypeFCMDefault: `Not set` | Accepted values: `PNPushTypeAPNS2`, `PNPushTypeFCM`. |
| `Topic`Type: stringDefault: `Not set` | APNs topic (bundle identifier). |
| `Environment`Type: PNPushEnvironmentDefault: `PNPushEnvironmentDevelopment` | APNs environment. Accepted values: `PNPushEnvironmentDevelopment`, `PNPushEnvironmentProduction`. |
| `QueryParam`Type: map[string]stringDefault: n/a | Map of query parameters to append to the API request. |

### Sample code

#### Remove all mobile push notifications (FCM)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_removeAllPushChannelsFCM demonstrates removing all channels from FCM push notifications
func Example_removeAllPushChannelsFCM() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// Remove all push notification channels for this FCM device
	// This is useful when a user logs out or uninstalls the app
	_, status, err := pn.RemoveAllPushNotifications().
		DeviceIDForPush("device-fcm-token"). // FCM device token
		PushType(pubnub.PNPushTypeFCM).      // Use FCM push type
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("All FCM push notifications removed")
	}

	// Output:
	// All FCM push notifications removed
}
```

#### Remove all mobile push notifications (APNs2)

```go
// Replace with your package name (usually "main")
package pubnub_samples_test

import (
	"fmt"

	pubnub "github.com/pubnub/go/v8"
)

// Example_removeAllPushChannelsAPNS2 demonstrates removing all channels from APNs2 push notifications
func Example_removeAllPushChannelsAPNS2() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo" // Replace with your subscribe key
	config.PublishKey = "demo"   // Replace with your publish key

	// snippet.hide
	config = setPubnubExampleConfigData(config)
	// snippet.show

	pn := pubnub.NewPubNub(config)

	// Remove all push notification channels for this APNs2 device
	// This is useful when a user logs out or uninstalls the app
	_, status, err := pn.RemoveAllPushNotifications().
		DeviceIDForPush("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"). // APNs device token (64 hex chars)
		PushType(pubnub.PNPushTypeAPNS2).                                                    // Use APNs2 push type
		Topic("com.example.myapp").                                                          // APNs topic (bundle identifier)
		Environment(pubnub.PNPushEnvironmentDevelopment).                                    // APNs environment
		Execute()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	if status.StatusCode == 200 {
		fmt.Println("All APNs2 push notifications removed")
	}

	// Output:
	// All APNs2 push notifications removed
}
```

### Returns

No payload is returned. Check `status.Error` on the status object.

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.
* **Push token** - A device identifier issued by a push provider (APNs or FCM) used to register a device for receiving mobile push notifications.