title: How to send a push notification from Node.js using REST API in MobileFirst Foundation 8?
body: <p>Who knows what did I wrong in implementing this on a Node.js server?</p>
  
  <p>The parameter were valid and it worked with the Poster on my local Mac.
  Node.js and MFP 8 Beta are running locally on the Mac. </p>
  
  <p><a href="https://i.stack.imgur.com/tyhvw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tyhvw.jpg" alt="enter image description here"></a></p>
  
  <p>Here is the code for the server.js file and the steps are: </p>
  
  <ol>
  <li>prepare the header </li>
  <li>MFP Settings</li>
  <li>create post options</li>
  <li>create the JSON object for MFP Push</li>
  <li>Do the POST call using http</li>
  <li><p>write the json Push Data</p>
  
  <pre><code>app.post('/award', function(req, res){
  var notificationMessage = req.body.message;
      // prepare the header
      // MFP Settings
      var theAuthorization = "Bearer eyJhbGciOiJSUzI1NiIsImp…….Wg";
      var appname = 'com.ionicframework.checkapp';
      var http = require('http');
      var theHost = 'localhost'; // here only the domain name
      var thePort = 9080;
      var thePath = 'imfpush/v1/apps/' + appname + '/messages';
      var theMethode = 'POST';
      var postheaders = {
      'Authorization' : theAuthorization ,
      'Content-Type'  : 'application/json'
      };
      // the post options
      var optionspost = {
      host : theHost,
      port : thePort,
      path : thePath,
      method : theMethode,
      headers : postheaders
      };
      // create the JSON object for MFP Push
      var jsonObject = JSON.stringify({"message":{"alert" :notificationMessage}});
      console.info('---&gt; Options prepared:');
      console.info(optionspost);
      console.info('---&gt; Do the POST call');
      // do the POST call using http
      var reqPost = http.request(optionspost, function(res) {
      console.log("---&gt; statusCode: ", res.statusCode);
      console.log("---&gt; headers: ", res.headers);
      res.on('data', function(d) {
       console.info('---&gt; POST result:\n');
       process.stdout.write(d);
       console.info('\n\n---&gt; POST completed');
      });
      });
      // write the json Push Data
      reqPost.write(jsonObject);
      reqPost.end();
      reqPost.on('error', function(e) {
      console.error(e);
      });
      res.end("OK");
    });
  </code></pre></li>
  </ol>
  
  <p>I get the statusCode:400 and this is console output:</p>
  
  <p>Options prepared:</p>
  
  <pre><code>{ host: 'localhost',
    port: 9080,
    path: 'imfpush/v1/apps/com.ionicframework.checkapp/messages',
    method: 'POST',
    headers: 
     { 'Content-Type': 'application/json',
       Authorization: 'Bearer eyJhbGciOiJSUzI1NiIsImp3ayI6......DjbgjqVz5JFVcT8i5k_JWg' } }
  ---&gt; Do the POST call
  ---&gt; statusCode:  400
  ---&gt; headers:  { 'content-length': '0',
    connection: 'Close',
    date: 'Wed, 22 Jun 2016 12:02:50 GMT' }
  </code></pre>
  
  <p>These were my information sources: 
  <a href="https://isolasoftware.it/2012/05/28/call-rest-api-with-node-js/" rel="nofollow noreferrer">https://isolasoftware.it/2012/05/28/call-rest-api-with-node-js/</a> and 
  <a href="https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/sending-push-notifications/" rel="nofollow noreferrer">https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/sending-push-notifications/</a></p>