Question: I am trying to use the data parameters to pass some JSON information with the notification. Notifications are successfully sent & received but the data parameter is not received.
The data parameter in Swift is as follows:
["retailerUserid": "25"]
The onPushReceived response is as follows:
{
alert = "Click to OK your payment to XXX for 100.04 USD.";
sound = default;
}, AnyHashable("p"): 6o]
The onPushAccepted response is as follows:
{
alert = "Click to OK your payment to XXX for 100.04 USD.";
sound = default;
}, AnyHashable("p"): 6o]
We were not able to pass “data” with the notifications. We read called /getMessageDetails and data = "<null>”; in the details.
Shown below is the /createMessage with message id “xxxxxxxxxxxx”.
urlString = "https://cp.pushwoosh.com/json/1.3/createMessage"
parameters = ["request": ["auth": "xxxxx", "devices": ["qwertyuiop1234567890"], "notifications": [["content": "Click to OK your payment to XXX for 100.04 USD.", "send_date": "now"]], "application": "ABCDE-12345", "data": "{\"retailerUserid\":\"25\"}”]]
Alamofire.request(urlString, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: nil).responseJSON {
response in
>
response = {
Messages = (
"ABCD-12345678-87654321"
);
};
"status_code" = 200;
"status_message" = OK;
}
Answer:
The format of your request is a bit incorrect:
parameters = ["request": ["auth": "xxxxx", "devices": ["qwertyuiop1234567890"], "notifications": [["content": "Click to OK your payment to XXX for 100.04 USD.", "send_date": "now"]], "application": "ABCDE-12345", "data": "{\"retailerUserid\":\"25\"}”]]
Please note that both "data" and "devices"/"users" key-value pairs should be included in an object in "notifications" array. Please refer to this guide for additional details:
https://www.pushwoosh.com/v1.0/reference#createmessage
In short, objects in "notifications" array represent individual pushes sent with particular parameters. Each push can have its own audience (be it a broadcast message to all users, a push to a segment, or a push to particular devices/users) and its own custom data. Therefore, you should pass these values inside an object in the array, and not vice versa.
Here is how your parameters should look like:
["request": [
"notifications": [
[
"data": "{\"retailerUserid\":\"25\"}",
"devices": ["qwertyuiop1234567890"],
"content": "Click to OK your payment to XXX for 100.04 USD.",
"send_date": "now",
],
"application": "ABCDE-12345",
"auth": "xxxxx”
]
]
Comments
0 comments
Please sign in to leave a comment.