3

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 }
  • 2
    Is your Firebase project on the free plan? Or on a paid plan? Making calls to 3rd party APIs is only allowed on a paid plan, to prevent abuse. See https://stackoverflow.com/questions/42774807/cloud-functions-for-firebase-getaddrinfo-enotfound – Frank van Puffelen Jul 25 '18 at 02:53

1 Answers1

2

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.

Prisoner
  • 49,922
  • 7
  • 53
  • 105