Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SyntaxError: Failed to parse JSON body: Unexpected token <] #243

Open
ghost opened this issue Aug 31, 2016 · 0 comments
Open

[SyntaxError: Failed to parse JSON body: Unexpected token <] #243

ghost opened this issue Aug 31, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Aug 31, 2016

I have the following piece of code.

// Method to generate manager with Q promises
function getFcmManager (socket) {
  // Define a client service constructor
  REST = restler.service(function (socket) {
    this.defaults.query = {
      // Query parameters here
    };
  }, {
    baseURL: API_PATH
  }, {
    POSTNOTIFICATION: function(object) {
      return this.post('send', {
        parser: restler.parsers.json,
        data: JSON.stringify(object),
        headers: {
          'Authorization': 'key=' + API_KEY,
          'Content-Type': 'application/json'
        }
      });
    }
  });
  // Create a client
  var rest = new REST(socket);
  // FCM manager
  var fcm = {
    // Post notification
    postnotification: function (token) {
      return Q.Promise(function (resolve, reject) {
        var settings = {
          notification: {
            title: "Notification title",  // Any value
            body: "Notification body",  // Any value
            sound: "default", // If you want notification sound
            click_action: "FCM_PLUGIN_ACTIVITY",  // Must be present for Android
            icon: "fcm_push_icon"  // White icon Android resource
          },
          data:{
            param1: "value1",  // Any data to be retrieved in the notification callback
            param2: "value2"
          },
          to: token, // Topic or single device
          priority: "high", // If not set, notification won't be delivered on completely closed iOS app
          restricted_package_name: "" // Optional. Set for application filtering
        }
        rest.POSTNOTIFICATION(settings).on('complete', function (data) {
          console.log('POSTNOTIFICATION', data);
          resolve(data);
        });
      });
    }
  }
  // Return
  return fcm;
}

And when I use:
fcm.postnotification(token);

It throws:
POSTNOTIFICATION [SyntaxError: Failed to parse JSON body: Unexpected token <]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants