Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making an API request on Firebase Cloud Functions

I'm trying to use OpenWeatherAPI for my Actions on Google project. I'm using Firebase Cloud Functions through Dialogflow. How can I make an API request to get data from OpenWeatherAPI?

request.get('http://api.openweathermap.org/data/2.5/uvi?appid=XXX&lat=37.75&lon=-122.37', function (error, response, body) {
          console.log('error:', error); 
          console.log('statusCode:', response && response.statusCode); 
          console.log('body:', body); 
        });

Here are Firebase logs:

statusCode: undefined

body: undefined

error: { Error: getaddrinfo ENOTFOUND api.openweathermap.org api.openweathermap.org:80
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.openweathermap.org',
host: 'api.openweathermap.org',
port: 80 }
like image 654
Evelina Jungblut Avatar asked Feb 25 '26 23:02

Evelina Jungblut


1 Answers

By default, Firebase Cloud Functions and the Dialogflow editor use a project that is on Firebase's Spark plan. This is completely free, but does have some restrictions, including no network access outside of Google's services.

In order to access openweathermap.org, you will likely need to upgrade to a paid plan. I suggest the Blaze plan, which is pay as you go over a certain level of usage each month. You will need to register with a credit card, but the usage level for development (and even for a modest level of production usage) should be enough to keep you in the free tier.

like image 138
Prisoner Avatar answered Feb 27 '26 14:02

Prisoner