Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49076

Invalid json in request body using ionic push

$
0
0

@eldy wrote:

couldn't find what's wrong with my req object. I got this error when trying to send push notification

**{"meta": {"status": 422, "version": "2.0.0-beta.0", "request_id": "28ac473b-4e7a-bd69"}, "error": {"link": null, "message": "Invalid JSON in request body. For empty JSON, pass '{}'.", "type": "UnprocessableEntity"}}**

router.post('/push', function(req, res) {

var title = req.body.title,
message = req.body.message;

// Define relevant info

var ionic_api_token = 'eyJ0eXAiOTdGb-xQVQaD2sV7qTh7XNKCnwiJKV1QiLJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI2MjiNC03YjE5LTQ3MzMtYjJhMy0zM2Y3MjBkYzU4MjcifQ.s3e6pCwlVUBAs8kvbO';
var device_tokens = ['d44pDarVamnNJS2cNJ2modyBxjZZxcHLlnhQN4wZkJdbgkOw96rq9EEv2WCA5MKU6do0pJoO5rsmQsBAecFt4OIFB0hhD4Dp2K-uMbjum828j-8LKtpCTtGoIDBUvYI6L'];
var ionic_security_profile = 'main';

// Build the request object
var req = {
method: 'POST',
url: 'https://api.ionic.io/push/notifications',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + ionic_api_token
},
data: {
"tokens": device_tokens,
"profile": ionic_security_profile,
"notification": {
"title": title,
"message": message,
"android": {
"title": title,
"message": message
},
"ios": {
"title": title,
"message": message
}
}
}
};

function callback(error, response, body) {
console.log(body)
}

request(req, callback);

});

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49076

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>