FCM Test Notification

Firebase Cloud Messaging (FCM) Postman Request Setup

🔥 Firebase Cloud Messaging (FCM)

Postman Request Setup Guide

1. Request Configuration

Method

POST

URL

https://fcm.googleapis.com/v1/projects/{YOUR_PROJECT_ID}/messages:send
Note: Replace {YOUR_PROJECT_ID} with your actual Firebase project ID

2. Headers

Key Value
Content-Type application/json
Authorization Bearer {ACCESS_TOKEN}

Getting the Access Token

You need a server key or OAuth 2.0 access token. For testing, you can:

Option A: Legacy Server Key

⚠️ Being deprecated

  • Go to Firebase Console → Project Settings → Cloud Messaging
  • Copy the Server Key
  • Use: key={SERVER_KEY} instead of Bearer {ACCESS_TOKEN}

Option B: OAuth 2.0 Token

Recommended

  • Use Google Cloud Console or gcloud CLI
  • Generate access token
  • Or use a service account key file

3. Request Body (JSON)

Basic Notification Example

{ "message": { "token": "YOUR_DEVICE_FCM_TOKEN_HERE", "notification": { "title": "Test Notification", "body": "This is a test message from Postman!", "image": "https://example.com/image.png" }, "data": { "key1": "value1", "key2": "value2", "click_action": "FLUTTER_NOTIFICATION_CLICK" } } }

Android-Specific Example

{ "message": { "token": "YOUR_DEVICE_FCM_TOKEN_HERE", "notification": { "title": "Android Test", "body": "Android specific notification" }, "android": { "priority": "HIGH", "notification": { "title": "Android Title Override", "body": "Android body override", "icon": "ic_notification", "color": "#FF0000", "sound": "default", "click_action": "MAIN_ACTIVITY", "channel_id": "default_channel" } }, "data": { "custom_data": "android_value" } } }

iOS-Specific Example

{ "message": { "token": "YOUR_DEVICE_FCM_TOKEN_HERE", "notification": { "title": "iOS Test", "body": "iOS specific notification" }, "apns": { "headers": { "apns-priority": "10" }, "payload": { "aps": { "alert": { "title": "iOS Title", "body": "iOS Body" }, "badge": 1, "sound": "default" }, "custom_key": "custom_value" } } } }

Web Push Example

{ "message": { "token": "YOUR_DEVICE_FCM_TOKEN_HERE", "notification": { "title": "Web Push Test", "body": "Web notification test" }, "webpush": { "headers": { "TTL": "300" }, "notification": { "title": "Web Override Title", "body": "Web override body", "icon": "https://example.com/icon.png", "badge": "https://example.com/badge.png" }, "fcm_options": { "link": "https://example.com" } } } }

4. Step-by-Step Postman Setup

  1. Create New Request
    Open Postman and click "New" → "Request"
  2. Set Method and URL
    Change method to POST and enter the FCM endpoint URL
  3. Add Headers
    Go to "Headers" tab and add Content-Type and Authorization headers
  4. Add Request Body
    Go to "Body" tab, select "raw" and "JSON", then paste your JSON payload
  5. Replace Placeholders
    Replace YOUR_DEVICE_FCM_TOKEN_HERE with actual device token
  6. Send Request
    Click "Send" and check response for success/error

5. Expected Response

Success Response (200 OK)

{ "name": "projects/your-project/messages/0:1234567890123456%abcdef123456" }

Error Response Examples

{ "error": { "code": 400, "message": "Invalid registration token", "status": "INVALID_ARGUMENT" } }

6. Testing Tips

🎯 Get Device Token

Make sure you have the correct FCM token from your test device

🔍 Check Project ID

Verify your Firebase project ID is correct in the URL

🔑 Token Validation

FCM tokens can expire, regenerate if needed

📱 Platform Testing

Test different payload structures for Android/iOS/Web

7. Common Issues

Invalid registration token: Token might be expired or incorrect
Authentication failed: Check your access token or server key
Project not found: Verify project ID in URL
Message too large: Payload exceeds size limits (4KB for most platforms)

8. Advanced Features

Targeting Multiple Devices

Replace token with topic or condition:

{ "message": { "topic": "news", "notification": { "title": "Breaking News", "body": "Important update for all subscribers" } } }

Scheduled Messages

Use fcm_options for scheduling:

{ "message": { "token": "YOUR_TOKEN", "notification": { "title": "Scheduled Message", "body": "This message was scheduled" }, "android": { "ttl": "3600s" } } }

Comments