title: Firebase Cloud Functions Error: connect ECONNREFUSED
body: <p>I am trying to create a Kik Messenger bot according to their <a href="https://dev.kik.com/#/docs/messaging#sending-messages" rel="noreferrer">API</a> using Firebase Cloud Functions. I am using Blaze Plan. I am trying to reply to a message that my bot received. I can receive messages on my API but when I try to reply to them I get an error. An error is not from the request callback. I see the error on Firebase Console.</p>
  
  <blockquote>
    <p><strong>Error: connect ECONNREFUSED 72.14.246.44:443</strong> </p>
    
    <blockquote>
      <p>at Object.exports._errnoException (util.js:1018:11)<br>
         at exports._exceptionWithHostPort (util.js:1041:20)<br>
         at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)<br>
         code: 'ECONNREFUSED',<br>
         errno: 'ECONNREFUSED',<br>
         syscall: 'connect',<br>
         address: '72.14.246.44',<br>
         port: 443  </p>
    </blockquote>
  </blockquote>
  
  <p>Requests to the Kik Messenger API works on local and remote node/express app. I tried to use <a href="https://github.com/kikinteractive/kik-node" rel="noreferrer">kik-node</a> on Cloud Functions but it gave the same result. What I have discovered so far is that <code>https://auth.kik.com</code> resolves to Amazon and <code>https://api.kik.com</code> resolves to Google Hosting. I think they are also using Firebase Cloud Functions for their API. Can it be possible that they are blocked inbound requests? Here is the sample code of what I tried.</p>
  
  <pre><code>exports.messagepost = functions.https.onRequest((req, res) =&gt; {
    // Gives the error below
    // {
    //  Error: connect ECONNREFUSED 72.14.246.44:443
    //   at Object.exports._errnoException (util.js:1018:11)
    //   at exports._exceptionWithHostPort (util.js:1041:20)
    //   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
    //   code: 'ECONNREFUSED',
    //   errno: 'ECONNREFUSED',
    //   syscall: 'connect',
    //   address: '72.14.246.44',
    //   port: 443
    // }
    request.post({
      uri: 'https://api.kik.com/v1/message',
      body: JSON.stringify({
        foo: 'bar'
      }),
      json: true,
      auth:{
        user:'{API_USER}',
        pass:'{API_KEY}'
      },
      headers: {
        'Content-Type'   : 'application/json'
      }
    }, (error, response) =&gt; {
      if (error) console.error(error);
      else console.log('Response: ', response.headers);
      res.status(200).end('OK');
    });
  });
  
  exports.messageget = functions.https.onRequest((req, res) =&gt; {
    // Gives the error below
    // {
    //  Error: connect ECONNREFUSED 72.14.246.44:443
    //   at Object.exports._errnoException (util.js:1018:11)
    //   at exports._exceptionWithHostPort (util.js:1041:20)
    //   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
    //   code: 'ECONNREFUSED',
    //   errno: 'ECONNREFUSED',
    //   syscall: 'connect',
    //   address: '72.14.246.44',
    //   port: 443
    // }
    request.get({
      uri: 'https://api.kik.com/v1/message',
      auth:{
        user:'{API_USER}',
        pass:'{API_KEY}'
      }
    }, (error, response) =&gt; {
      if (error) console.error(error);
      else console.log('Response: ', response.headers);
      res.status(200).end('OK');
    });
  });
  
  exports.verificationget = functions.https.onRequest((req, res) =&gt; {
    // Runs with no errors
    request.get({
      uri: 'https://auth.kik.com/verification/v1/check',
      qs: {
        u: 'username',
        d: 'hostname',
        debug: true
      },
      body: JSON.stringify({ data: 'debugsigneddata' }),
      headers: {
        'Content-Type'   : 'application/json' ,
        'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
      },
      auth:{
        user:'{API_USER}',
        pass:'{API_KEY}'
      }
    }, (error, response) =&gt; {
      if (error) console.error(error);
      else console.log('Response: ', response.headers);
      res.status(200).end('OK');
    });
  });
  
  exports.verificationpost = functions.https.onRequest((req, res) =&gt; {
    // Runs with no errors
    request.post({
      uri: 'https://auth.kik.com/verification/v1/check',
      qs: {
        u: 'username',
        d: 'hostname',
        debug: true
      },
      body: JSON.stringify({ data: 'debugsigneddata' }),
      headers: {
        'Content-Type'   : 'application/json' ,
        'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
      },
      auth:{
        user:'{API_USER}',
        pass:'{API_KEY}'
      }
    }, (error, response) =&gt; {
      if (error) console.error(error);
      else console.log('Response: ', response.headers);
      res.status(200).end('OK');
    });
  });
  </code></pre>