---
source_url: https://www.pubnub.com/docs/sdks/go/api-reference/misc
title: Utility Methods API for Go SDK
updated_at: 2026-06-19T11:37:24.077Z
sdk_name: PubNub Go SDK
sdk_version: v9.0.1
---

> 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


# Utility Methods API for Go SDK

PubNub Go SDK, use the latest version: v9.0.1

Install:

```bash
go get github.com/pubnub/go/v9@v9.0.1
```

The methods on this page are utility methods that don't fit into other categories.

## Create push payload

This method creates the push payload for use in the appropriate endpoint calls.

### Method(s)

```go
CreatePushPayload().
    SetAPNSPayload(pubnub.PNAPNSData,[]pubnub.PNAPNS2Data).
    SetCommonPayload(map[string]interface{}).
    SetFCMPayload(pubnub.PNFCMData).
    BuildPayload()
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| SetAPNSPayload | pubnub.PNAPNSData | Optional |  | Set APNS Payload. Associated APNS devices will receive only the data within the `pn_apns` key. |
| SetAPNSPayload | []pubnub.PNAPNS2Data | Optional |  | Set APNS2 Payload. Associated APNS devices will receive only the data within the `pn_push` key. |
| SetFCMPayload | pubnub.PNFCMData | Optional |  | Set FCM Payload. Associated FCM devices will receive only the data within the `pn_fcm` key. |
| SetCommonPayload | map[string]interface | Optional |  | Set Common Payload. Native PubNub subscribers will receive the entire object literal, including the `pn_apns`, `pn_fcm`, and `common payload`. |
| BuildPayload |  | Yes |  | Builds the payload from the values set using the parameters. Returns a `map[string]interface{}` |

### Sample code

#### Create push payload

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

import (
	"fmt"

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

// Example_createPushPayloadCombined demonstrates creating a combined push payload for both APNS and FCM
func Example_createPushPayloadCombined() {
	config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
	config.SubscribeKey = "demo"
	config.PublishKey = "demo"

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

	pn := pubnub.NewPubNub(config)

	// Create APNS payload
	apnsPayload := pubnub.PNAPNSData{
		APS: pubnub.PNAPSData{
			Alert: "New message!",
			Badge: 1,
			Sound: "default",
		},
	}

	// Create FCM payload
	fcmPayload := pubnub.PNFCMData{
		Data: pubnub.PNFCMDataFields{
			Summary: "New message!",
		},
	}

	// Create common payload for regular PubNub subscribers
	commonPayload := map[string]interface{}{
		"text":      "New message!",
		"timestamp": "2024-01-01T00:00:00Z",
	}

	// Build combined push payload
	pushPayload := pn.CreatePushPayload().
		SetAPNSPayload(apnsPayload, nil).
		SetFCMPayload(fcmPayload).
		SetCommonPayload(commonPayload).
		BuildPayload()

	// Publish the combined push payload
	response, status, err := pn.Publish().
		Channel("notification-channel").
		Message(pushPayload).
		Execute()

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

	if status.StatusCode == 200 && response.Timestamp > 0 {
		fmt.Println("Combined push payload published successfully")
	}

	// Output:
	// Combined push payload published successfully
}
```

### Response

The `CreatePushPayload()` operation returns a `map[string]interface{}` which can be passed directly to the `Publish` Method's `Message` parameter.