Push Notification - communication with a server


#1

Hello!

I’m trying Push Notification. I did the tutorial from Ionic 2: http://docs.ionic.io/services/push/

All worked perfectly, I succeeded to get my device token and I was able to send Push Notification with the service from Ionic. But what next now? For example, when a button is clicked in the application, I would like that the application sends a request to a server such that it send to the smartphone a notification. I read several tutorials on Internet but most of them seem outdated (or maybe it is just me who was not able to understand correctly the tuto…). For example, I was thinking to do that:

var req = {
            method: 'POST',
            url: 'https://api.ionic.io/push/notifications',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + this.APItoken
            },
            data: {
                "tokens": 'My_token',
                "profile": 'test',
                "notification": {
                    "title": this.titlePush,
                    "message": this.messagePush,
                    "android": {
                        "iconColor": "#ee9425",
                        //"stack": 3,
                        "title": this.titlePush,
                        "message": this.messagePush
                    },
                    "ios": {
                        "title": this.titlePush,
                        "message": this.messagePush
                    }
                }
            }
        };

But is that correct? If yes, where am I suppose to write that in my code? How to use it in practice? Maybe with Http? How?