-
Notifications
You must be signed in to change notification settings - Fork 10
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
"registration_ids" field is not a JSON array #8
Comments
I get the same thing. I don't believe the JSON message is being parsed correctly before being sent. Haven't tracked down the exact code location yet. |
Edit: This will only work for less than 1000 devices, the real fix for the issue is here lemonlabs@87484d2
Sender.prototype._sendJSONRequest = function (options, attemptOptions, message, registration_ids, callback) {
var self = this;
message['registration_ids'] = registration_ids;
options['headers']['Content-Type'] = 'application/json; charset=utf-8';
options['headers']['Content-length'] = Buffer.byteLength(JSON.stringify(message), 'utf8');
if (!util.isArray(registration_ids)) return callback(new Error('registration_ids must be an array'));
var multicastResult = new MulticastResult();
options['body'] = JSON.stringify(message);
debug('HTTP OPTIONS > %s', JSON.stringify(options));
attempt(
function (attempts) {
debug('DEBUG > attempts : %s', attempts);
self._sendRequest(options, this);
},
attemptOptions,
function (err, data) {
if (err) return callback(err);
try {
data = JSON.parse(data);
multicastResult.addMulticastId(data.multicast_id);
multicastResult.setSuccessLength(data.success);
var results = data.results;
for (var i = 0; i < results.length; i++) {
if (results[i].hasOwnProperty('registration_id')) {
multicastResult.addCanonicalIdObject({
message_id: results[i].message_id,
registration_id: registration_ids[i],
new_registration_id: results[i].registration_id
});
} else if (results[i].hasOwnProperty('error')) {
multicastResult.addFailureValueWithKey(results[i].error, registration_ids[i]);
}
}
callback(null, multicastResult.toJSON());
} catch (ex) {
callback(ex);
}
}
);
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I use the
message.toJSON()
I always get aError: BAD_REQUEST : Request could not be parsed as JSON, or it contained invalid fields
with the following details"registration_ids" field is not a JSON array
.Here is my code:
If I send the message using
message.toString()
everything goes well.Am I doing something wrong?
Do I need to declare the registrationIds array differently?
The text was updated successfully, but these errors were encountered: