Reputation: 34780
I'm trying to send a JSON notification to APNS and when I try to send it I'm getting 400 Bad Request with the error message:
The supplied notification payload is invalid.
Here is my Notification JSON:
{"uri":"myApp://test","type":"test_push","badge":1,"content-available":1}
I create the notification like this:
notif = new AppleNotification(json);
I'm sending the notification:
client.SendNotificationAsync(notif, "myTag")
After that, I'm getting the error. The content type is application/xml
by default, after I got the error, I've started setting the content type to application/json
but nothing changed.
What am I doing wrong?
UPDATE: My hub and certificates are installed correctly; I can send a successful test notification through Azure Portal.
Upvotes: 3
Views: 3815
Reputation: 1421
You can escape special characters using \. See in example below I have used double quote for word Hub which escape using \.
{"aps":{"alert":"Notification \\\"Hub\\\" test notification"}}
Upvotes: 0
Reputation: 1522
Can,
Your payload is malformed, please try with the following:
{"aps":{"uri":"myApp://test","type":"test_push","badge":1,"content-available":1}}
Upvotes: 4
Reputation: 34780
After playing with the test push sending on Azure Portal, I've discovered the problem myself: Notification Hub wasn't accepting the JSON if it wasn't already wrapped in aps
object. I've changed the JSON to be sent as:
{aps: {"uri":"myApp://test","type":"test_push","badge":1,"content-available":1} }
and now it's working. I thought it was auto wrapping, but apparently it isn't.
Upvotes: 2