title: Invalid Registration FCM in API using Entity framework
body: <p>I am trying to get DeviceToken of device in Xamarin iOS through RegisteredForRemoteNotifications and save it to Preferences, through API I save DeviceToken to database Server.</p>
  <p>AppDelegate.cs</p>
  <pre><code>public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
  {
      byte[] bytes = deviceToken.ToArray&lt;byte&gt;();
      string[] hexArray = bytes.Select(b =&gt; b.ToString(&quot;x2&quot;)).ToArray();
      DeviceToken = string.Join(string.Empty, hexArray);
  
      Preferences.Set(&quot;TokenDevice&quot;, DeviceToken);
  }
  </code></pre>
  <p>I have saved the DeviceToken to the database, the DeviceToken of the device I get:</p>
  <pre><code>6b60feecad920471ccde5a3447ab22d3f820abae821daeac726cc7e6d0863465
  </code></pre>
  <p>I wrote an API to send notifications to that device:</p>
  <pre><code>[HttpPost]
  public void SendNotification(string devicetoken, string title, string body, string link, string icon)
  {
      try
      {
          dynamic data = new
          {
              to = devicetoken, // Uncoment this if you want to test for single device
                                // registration_ids = singlebatch, // this is for multiple user 
              priority = &quot;high&quot;,
              notification = new
              {
                  title = title,     // Notification title
                  body = body,    // Notification body data
                  link = link,       // When click on notification user redirect to this link
                  icon = icon
              }
          };
  
          //var serializer = new JavaScriptSerializer();
          var json = JsonConvert.SerializeObject(data);
          Byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(json);
  
          string SERVER_API_KEY = &quot;AAAAqOId6Is:APA91bHJ5pQgLlanU8gwQwnpxdBlKS00i1xxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;;
          string SENDER_ID = &quot;72xxxxxxxx&quot;;
  
          WebRequest tRequest;
          tRequest = WebRequest.Create(&quot;https://fcm.googleapis.com/fcm/send&quot;);
          tRequest.Method = &quot;post&quot;;
          tRequest.ContentType = &quot;application/json&quot;;
          tRequest.Headers.Add(string.Format(&quot;Authorization: key={0}&quot;, SERVER_API_KEY));
  
          tRequest.Headers.Add(string.Format(&quot;Sender: id={0}&quot;, SENDER_ID));
  
          tRequest.ContentLength = byteArray.Length;
          Stream dataStream = tRequest.GetRequestStream();
          dataStream.Write(byteArray, 0, byteArray.Length);
          dataStream.Close();
  
          WebResponse tResponse = tRequest.GetResponse();
  
          dataStream = tResponse.GetResponseStream();
  
          StreamReader tReader = new StreamReader(dataStream);
  
          String sResponseFromServer = tReader.ReadToEnd();
  
          tReader.Close();
          dataStream.Close();
          tResponse.Close();
      }
      catch (Exception)
      {
          throw;
      }
  }
  </code></pre>
  <p>Where: SERVER_API_KEY and SENDER_ID I got from in console.firebase.google.com/Project settings/Cloud Messaging</p>
  <p><a href="https://i.stack.imgur.com/IGPmM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IGPmM.png" alt="enter image description here" /></a></p>
  <p>I tried to test the API that sends notifications to the device I get the error: <code>{\&quot;multicast_id\&quot;:7343900550378569449,\&quot;success\&quot;:0,\&quot;failure\&quot;:1,\&quot;canonical_ids\&quot;:0, \&quot;results\&quot;:[{\&quot;error\&quot;:\&quot;InvalidRegistration\&quot;}]}</code></p>
  <p><a href="https://i.stack.imgur.com/K4AWr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K4AWr.png" alt="enter image description here" /></a></p>
  <p><strong>I referenced this <a href="https://firebase.google.com/docs/cloud-messaging/send-message#send_messages_to_specific_devices" rel="nofollow noreferrer">article</a>. However I want to use this code because it allows me to set the Notification link and icon. Is this an outdated notification code? I searched the forums, and didn't get any reasonable results. Looking forward to everyone's help.</strong></p>