firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
370 stars 131 forks source link

Issue Sending FCM Message: "Operation is not implemented, or supported, or enabled #425

Closed SathishkumarG3 closed 1 month ago

SathishkumarG3 commented 1 month ago

[READ] Step 1: Are you in the right place?

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

  1. We are trying to send FCM notifications using Firebase Admin SDK (v3.0.1).
  2. The code constructs a MulticastMessage and attempts to send it using SendMulticastAsync.
  3. The request fails with the following error:
Exception = {"**Operation is not implemented, or supported, or enabled**."}
HttpResponse = {StatusCode: 501, ReasonPhrase: 'Not Implemented', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Vary: Origin, X-Origin, Referer
  Content-Type: application/json; charset=utf-8
  Content-Length: 144
}}
Data = {System.Collections.ListDictionaryInternal}

Relevant Code:

public async Task<string> SendFCM(FCMRequestModel request)
{
    try
    {
        var Tokens = request.registration_ids;
        var notification = request.mobile_center;

        // Create a Dictionary to store the key-value pairs from FCMData
        Dictionary<string, string> dataDictionary = new Dictionary<string, string>();

        // Iterate through each FCMData and add it to the Dictionary
        foreach (var fcmData in request.data ?? Array.Empty<FCMData>())
        {
            dataDictionary[fcmData.Key] = fcmData.Value;
        }

        var message = new MulticastMessage()
        {
            Data = dataDictionary,
            Tokens = Tokens,
            Notification = new()
            {
                Body = request.notification.body,
                Title = request.notification.title,
                ImageUrl = notification?.IMAGE,
            },
        };

        // Send a message to the devices.
        var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message);

        // Serialize the response object to JSON
        string jsonResponse = JsonConvert.SerializeObject(response.Responses);

        //Response is a message ID string.
        return jsonResponse;
    }
    catch (Exception ex)
    {
        _logger.LogError(ex, "{message}", ex.Message);
        throw;
    }
}

What happened:

We received the error mentioned above when trying to send FCM notifications.

Expected behavior:

The FCM messages should be successfully sent to the specified device tokens.

google-oss-bot commented 1 month ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

lahirumaramba commented 1 month ago

SendAllAsync() and SendMulticastAsync() APIs were deprecated in v2.4.0. Use SendEachAsync() and SendEachForMulticastAsync() APIs instead.

See release notes.