I'm encountering a problem with my Ionic application. I am trying to make use of the Rest API for send push notifications with Parse. I can use their push console to successfully send notifications.
However the following function throws error code 115 and a message saying "error: "Missing the push data." Please let me know if you need any other information for the issue.
Thank you.
$scope.send = function()
{
$http({
url: "https://api.parse.com/1/push",
method: "POST",
data: {
"alert": "Alert Message", //not platform specific
"badge": "1", //platform specific iOS
"sound": "", //platform specific iOS
"channels":["test"]
},
headers: {
"X-Parse-Application-Id": "removed",
"X-Parse-REST-API-Key": "removed",
"Content-Type": "application/json"
}
}).success(function (data, status, headers, config) {
console.log("Push sent!");
//alert('iOS registered success = ' + data + ' Status ' + status);
}).error(function (data, status, headers, config) {
console.log(config)
});
};
I have come up with a solution. The following works with the REST API:
$scope.send = function()
{
$http({
"url": "https://api.parse.com/1/push",
"method": "POST",
"data": {
"data": { "alert": "Alert Message", "sound": "", "badge": "Increment" },"channel":""
// this line needed correct JSON formatting
},
"headers": {
"X-Parse-Application-Id": "removed",
"X-Parse-REST-API-Key": "removed",
"Content-Type": "application/json"
}
}).success(function (data, status, headers, config) {
console.log("Push sent!");
//alert('iOS registered success = ' + data + ' Status ' + status);
}).error(function (data, status, headers, config) {
console.log(config)
});
};
I didn't have the correct JSON key-value formatting. Hope this helps others when using Angular to make HTTP POST requests using the Parse REST API.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.