Repository navigation
"registration_ids" field is not a JSON array #8
Copy link
Copy link
Open
Description
Activity
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
This version works properly, sends to all devices with one requestSender.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); } } ); };
Metadata
Metadata
Assignees
Labels
No labels
If I use the
message.toJSON()I always get aError: BAD_REQUEST : Request could not be parsed as JSON, or it contained invalid fieldswith 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?