4

I'm using Pinpoint to push notifications through FCM and I'm receiving an error back from AWS:

{
    "ApplicationId": "xxx",
    "RequestId": "yyy",
    "EndpointResult": {
        "5551212": {
            "DeliveryStatus": "PERMANENT_FAILURE",
            "StatusCode": 410,
            "StatusMessage": "{\"errorMessage\":\"Unregistered or expired token\",\"channelType\":\"GCM\",\"pushProviderStatusCode\":\"200\",\"pushProviderError\":\"InvalidRegistration\",\"pushProviderResponse\":\"{\\\"multicast_id\\\":752174934090126,\\\"success\\\":0,\\\"failure\\\":1,\\\"canonical_ids\\\":0,\\\"results\\\":[{\\\"error\\\":\\\"InvalidRegistration\\\"}]}\"}",
            "Address": "userID"
        }
    }

An oddity is that when the app is launched/loaded the Amplify.config is not calling the PushNotification.onRegister function either:

const amplifyConfig = {
      Auth: {
        identityPoolId: POOL_ID,
        region: 'us-east-1'
      },
      Analytics: {
        AWSPinpoint: {
              appId: APP_ID,
              region: 'us-east-1',
              mandatorySignIn: false,
              endpointId: '5551212',
              endpoint: { 
                address: 'userID',
                channelType: 'GCM',
                optOut: 'NONE'
              }
        }
      }
    }

    PushNotification.onRegister(t => console.log(`Registration token: ${t}`), onRegister && onRegister());
    PushNotification.onNotification(n => (console.log(n), onNotification && onNotification(n)));
    PushNotification.onNotificationOpened(n => (console.log(n), onNotificationOpened && onNotificationOpened(n)));
    Amplify.configure(amplifyConfig);
Patrick Dench
  • 813
  • 2
  • 9
  • 27
  • Did you ever solve this? – Fook Mar 04 '19 at 02:54
  • Nope... still fighting this one... – Patrick Dench Mar 04 '19 at 14:43
  • any updates on this??? – Aslam Jul 26 '19 at 12:08
  • I ended up writing a module to retrieve the token directly. – Patrick Dench Jul 27 '19 at 15:59
  • Hi, I tried getting token from Firebase directly and once I am logged in, i am updating the endpoint with deviceToken with below configuration: ``` await Analytics.updateEndpoint({ // address: fcmToken, channelType: "GCM", userId: uid, optOut: 'NONE', }); ``` Seems like it worked and I am able to send push notification to my device. After some time like 20 mins or so if I try to push notification I am getting this error: "StatusCode": 410, "StatusMessage": "{\"errorMessage\":\"Unregistered or expired token Any idea why its coming? – Munish Mar 02 '21 at 01:32

1 Answers1

1

Edit: Your error seems related to Invalid Registration token: Make sure the endpoint address matches the registration token the client app receives from registering with FCM - https://developers.google.com/cloud-messaging/http-server-ref#error-codes).

I managed to make it work after login by getting the deviceToken from AsyncStorage.

If you want to keep the endpointId and only update the userId (only one user is logged in at each time - remember you can send push notifications to a specific userId that can have multiple endpoints (devices, email, phone number)):

try {
  const deviceToken = await AsyncStorage.getItem('push_token'+aws_exports.aws_mobile_analytics_app_id)
  if (deviceToken !== null) {
    console.log('device token from AsyncStorage', deviceToken)
    Analytics.updateEndpoint({
      optOut: 'NONE',
      channelType: 'GCM',
      userId: userId,
      address: deviceToken,
    })
  }
} catch (error) {
  console.log('error retrieving device token from AsyncStorage', error)
}

OR, if you want to specify your own endpointId (this way you can have multiple users/endpoints in the same device):

try {
  const deviceToken = await AsyncStorage.getItem('push_token'+aws_exports.aws_mobile_analytics_app_id)
  if (deviceToken !== null) {
    console.log('device token from AsyncStorage', deviceToken)
    Analytics.configure({
      disabled: false,
      AWSPinpoint: {
        appId: aws_exports.aws_mobile_analytics_app_id,
        region: aws_exports.aws_mobile_analytics_app_region,
        endpointId: endpointId,
        endpoint: {
          address: deviceToken,
          channelType: 'GCM',
          optOut: 'NONE',
          userId: userId
        }
      }
    })
    Analytics.updateEndpoint({
      optOut: 'NONE',
    })
  }
} catch (error) {
  console.log('error retrieving device token from AsyncStorage', error)
}

First, check your debug messages using window.LOG_LEVEL='DEBUG'

Then, make sure Analytics is working! Configure the Analytics module before the Push Notification module (https://aws-amplify.github.io/docs/js/push-notifications#configure-your-app). Do you have a call to PushNotification.configure()?

As far as I know, you need to have PushNotification.onRegister() called to get a valid active targetable endpoint.

Are you testing in a real device?

And what happens if you don't set the endpointId and endpoint attributes on your amplifyConfig? It should update your endpoint address with the device token on its own. You can later on update your endpoint with the user id Analytics.updateEndpoint({optOut: 'NONE', UserId: 'xxx'})

ps.: I was having a related issue and now is finally working, but I set up my backend with Amplify CLI so it may be slightly different

  • If I remove the following endpointId: '5551212', endpoint: { address: 'userID', channelType: 'GCM', optOut: 'NONE' } It registers the Device ID and I can send to it, but I can't specify the endpointId in the updateEndpoint function call. – Patrick Dench Mar 07 '19 at 19:02
  • Oh, and to answer your other questions, I am calling PushNotification.configure(), and yes I'm testing with a real device. My struggle is that I want to send to an endpoint ID, or some other identifier instead of a device ID, as we'll have multiple users on a device. – Patrick Dench Mar 07 '19 at 19:09
  • hey @PatrickDench I improved my answer, can you check if it helps you now? – Gabriela Thumé Mar 14 '19 at 18:20
  • I'll take a look - I hacked a work around using a RN module for the time being. Pretty nasty, but... – Patrick Dench Mar 27 '19 at 15:16