Make https request within Firebase functions.https.onRequest

555 views
Skip to first unread message

Mike Lefa

unread,
Jun 28, 2017, 11:38:19 AM6/28/17
to Firebase Google Group

Hi there,

Does anymore knows how I can make https request from within firebase functions.https.onRequest? I have written the code shown below but It keeps throwing an error:

Error: getaddrinfo ENOTFOUND test.oppwa.com test.oppwa.com:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

My code is as follow:

exports.MyTestFunction = functions.https.onRequest((req, res) => {

         
var path = '/v1/checkouts';
               
var data = querystring.stringify({
                       
                       
'authentication.userId' : '8a8294174b7ecb28014b9699220015cc',
                       
'authentication.password' : 'sy6KJsT8',
                       
'authentication.entityId' : '8a8294174b7ecb28014b9699220015ca',
                       
'amount' : '92.00',
                       
'currency' : 'EUR',
                       
'paymentType' : 'DB',
                       
'shopperResultUrl' : 'my.app://custom/url',
                       
'notificationUrl' : 'http://www.example.com/notify'
               
});
               
               
               
var options = {
                        port
: 443,
                        hostname
: 'test.oppwa.com',
                        path
: path,
                        method
: 'POST',
                        headers
: {
                               
'Content-Type': 'application/x-www-form-urlencoded',
                               
'Content-Length': data.length
                       
}
               
};
               
               
var postRequest = http.request(options, function(res){
                       
                        console
.log('statusCode: ', res.statusCode);
                        console
.log('headers: ', res.headers);
                       
                        res
.setEncoding('utf8');
                        res
.on('data', function (chunk) {
                                jsonRes
= JSON.parse(chunk);
                               
                                console
.log('Data Response 1: ', jsonRes);
                               
                               
return callback(jsonRes);
                       
});
                       
                        res
.on('error', (error)=> {
                               
                                console
.error('ERROR: ', error)
                               
                       
});
                       
               
});
               
                postRequest
.write(data);
                postRequest
.end();

}



Doug Stevenson

unread,
Jun 28, 2017, 4:56:08 PM6/28/17
to Firebase Google Group
You should be able to make outbound HTTP requests to destinations outside of Google if your project is on the Blaze payment plan.  That error message is a symptom of not having billing enabled.

Doug
Reply all
Reply to author
Forward
0 new messages