Reputation: 3150
I've been trying to operate the POST request api for sending push notifications for multiple users and encountered in the following problem.
The endpoint doesn't parse the 'contents' parameter and so breaks the endpoint.
Here is my request:
POST /api/v1/notifications HTTP/1.1
Host: onesignal.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
app_id=e10b31ff-e4f4-4692-be1b-2d1cf76a7d55&contents=%7B+%22en%22+%3A+%22Message%22+%7D&isAndroid=true&include_player_ids%5B%5D=9918cda9-45a7-4ee2-9865-4da42fe346cf
the contents is { "en" : "Message" } which is exactly as it should be in case the push's message is in English.
Seems like a dead end to me.
Upvotes: 0
Views: 430
Reputation: 3150
So finally I was managed to do it simply by adding all the required params into a single json, add it to the request's body and set the header's Content-type on application/json so that OneSignal's server would know about the request body's type.
In addition I had a formatting problem as @jwilm stated above. I'm developing on Java so I was managed to fix it using URLEncoder.
Upvotes: 0
Reputation: 447
Running your contents
param through decodeURIComponent
returns "{+"en"+:+"Message"+}"
which is not valid JSON. I am guessing that your JSON has spaces in it that were not encoded properly.
Upvotes: 1