Saturday 3 June 2017

Passing array in body of request npm

I have to send some parameters of String type along with one array in my body. But it throws me an error message First argument must be String or buffer

Here is my code

var tokenList = JSON.parse(req.body.tokenList);
    var mobParams = {
        "tokens": tokenList,
        "profile": "<myprofile>",
        "notification": {
            "title": req.body.title,
            "message": req.body.text
        }
    };

     request({
        method: "POST",
        url: 'https://api.ionic.io/push/notifications',
        headers: {
            "content-type": "application/json",
            "authorization": "Bearer ********"
        },

        body: (mobParams)

     }, function(error, response, body){
        console.log('Ionic push error', error);
        console.log('IOnic push res', response);
        console.log('IOnic push body', body);
        if(!error){
            return res.send({
                code: 1,
                message: "success"
            });
        }else{
            return res.send({
               code: 0,
                message: error
            });
        }

How can I pass my array inside this object to request npm.



via MegaRacer

No comments:

Post a Comment