Onesignal Rest API Push Notification in Ionic App and Angular JS Javascript
18-03-2017We can use following Javascript & Angular JS code to send push notification in OneSignal by using FILTER property:
var content={}; content.en="Test message"; var filters=[]; filter={}; filter.field="tag"; filter.key="authorId"; filter.relation="="; filter.value=54; filters.push(filter); parameter = JSON.stringify({ app_id: "31ee45e2-c63d-4048-903a-89ca43f3afa4", contents:content, filters: filters }); $http.post("https://onesignal.com/api/v1/notifications", parameter, { headers: { 'Authorization': 'Basic YzUzNmZkOTAtMmVlMC00OWIzLThlNGQtMzQyYzIyNmFhZjcw', 'Content-Type': 'application/json; charset=utf-8' } }).success(function (data) { console.log(data); $scope.showAlert("İşlem Sonucu", "Sorunuz başarılı bir şekilde iletildi"); }).error(function (data) { $scope.showAlert("Hata", "Sorunuz iletilirken hata oluştu"); });
At line 12, 31ee45e2-c63d-4048-903a-89ca43f3afa4 is APP ID,
At line 1 YzUzNmZkOTAtMmVlMC00OWIzLThlNGQtMzQyYzIyNmFhZjcw is Onesignal REST API KEY