Firebase Cloud Messaging (FCM) has deprecated its Legacy API in favor of the more secure and feature-rich HTTP v1 API. Upgrading ensures continued support, enhanced security, and access to the latest Firebase capabilities.
Why Migrate to HTTP v1 API?
The HTTP v1 API offers several advantages:
- Improved security with OAuth 2.0 authentication
- Better message customization
- Platform-specific configuration support
- Enhanced scalability and future compatibility
- Continued support from Firebase
Step 1: Enable Firebase Cloud Messaging API
Open the Firebase Console and ensure the Firebase Cloud Messaging API is enabled for your project.
Firebase Console:
https://console.firebase.google.com/
Step 2: Create a Service Account
In Google Cloud Console:
- Navigate to IAM & Admin
- Create or select a Service Account
- Generate a JSON private key
- Download the credentials file securely
Google Cloud Console:
https://console.cloud.google.com/
Step 3: Generate an OAuth 2.0 Access Token
Unlike the Legacy API that uses a Server Key, HTTP v1 requires OAuth 2.0 access tokens generated from your service account credentials.
Step 4: Update the API Endpoint
Replace the legacy endpoint:
with:
Step 5: Update Request Format
The HTTP v1 API uses a new JSON structure:
{
“message”: {
“token”: “DEVICE_TOKEN”,
“notification”: {
“title”: “Hello”,
“body”: “Welcome to our app”
}
}
}
Step 6: Test Message Delivery
Send test notifications and verify successful delivery across Android, iOS, and web applications.
Best Practices
- Store service account credentials securely.
- Use OAuth token refresh mechanisms.
- Test thoroughly before production deployment.
- Monitor Firebase logs for errors and delivery status.
Useful Resources
- Firebase Cloud Messaging Documentation:
https://firebase.google.com/docs/cloud-messaging - HTTP v1 API Migration Guide:
https://firebase.google.com/docs/cloud-messaging/migrate-v1 - FCM REST API Reference:
https://firebase.google.com/docs/reference/fcm/rest
Conclusion
Migrating from the FCM Legacy API to the HTTP v1 API is essential for maintaining secure and reliable push notifications. By adopting OAuth-based authentication and the updated messaging format, developers can ensure their applications remain compatible with Firebase’s latest standards and future updates.