1
votes

Hello guys i am working on ionic ios push notification and stuck into the last thing where i am trying to test notification in my device.

I have followed every steps shown in ionic docs for full push setup for ios. Like adding plugins, creating certificates and uploading the .p12 file in ionic io app settings and creating a profile. The build also succeeds in xcode and the dev notification where it shows an alert message is also working fine.

The thing is that by default is has the profile "fake_profile_push" which i was trying to replace with the one that i made in the ionic io app setting named "push_profile". i made sure the config dev push to false.

So here i am trying to send this curl command from terminal where i copied the auth code from ionic io , profile as made and token taken from the console log.

curl -X POST -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5NTk5MGFiZi04ZTljLTQ5YjktOTc1Yy0zMDA1OGI3ZThiY2UifQ.KubeC0N764OWE_SZDxJRdY6ie266CVvLX8OwNnm6rr8" -H "Content-Type: application/json" -d '{
    "tokens": ["DEV-8180d41f-adc0-4b11-b0cc-7fa6370adad7],
    "profile": “push_profile”,
    "notification": {
        "message": "Hello!"
    }
}' "https://api.ionic.io/push/notifications"

It returns me json error which i do not understand

{"error": {"link": null, "type": "UnprocessableEntity", "message": "Invalid JSON in request body. For empty JSON, pass '{}'."}, "meta": {"status": 422, "version": "2.0.0-beta.0", "request_id": "7dec664f-ae0b-4a8a-807b-edee70b4a1e5"}}

i do not see any error in the request body. What am i doing wrong? Can you correct me please? Thank You

Your system information:

Cordova CLI: 6.0.0
Gulp version:  CLI version 3.9.1
Gulp local:  
Ionic Version: 1.2.4
Ionic CLI Version: 1.7.14
Ionic App Lib Version: 0.7.0
ios-deploy version: Not installed
ios-sim version: 5.0.6 
OS: Mac OS X El Capitan
Node Version: v5.9.0
Xcode version: Xcode 7.2.1 Build version 7C1002 
2

2 Answers

1
votes
"tokens": ["DEV-8180d41f-adc0-4b11-b0cc-7fa6370adad7],

should be:

"tokens": ["DEV-8180d41f-adc0-4b11-b0cc-7fa6370adad7"],

I guess that caused the json error

0
votes

You can check the status of your push making a GET request to the following endpoint: https://api.ionic.io/push/notifications/<your-notification-uuid>/messages

I think the problem is in your headers. Proof if your Authorization: Bearer is correct. You can test your token : curl -H "Authorization: Bearer [YOUR_TOKEN]" https://api.ionic.io/auth/test

Also, try removing -H "Content-Type: application/json" from your request because the error says the problem is in the json.