2
votes

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.

3
Can, can you confirm you've uploaded the certificate?Vivien Chevallier
@VivienChevallier yes, and I can send a test notification from Azure Portal successfully.Can Poyrazoğlu

3 Answers

4
votes

Can,

Your payload is malformed, please try with the following:

{"aps":{"uri":"myApp://test","type":"test_push","badge":1,"content-available":1}}
2
votes

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.

0
votes

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"}}