0

I'm trying to make a GET request to an HTTPS service ( https://broker.bronos.net ). This service is an API that communicates with a client on my LAN. I can't get it to work via functions.https.get(URL, (s,ss) => {});

Please help -- I'm very new to web development, let alone google actions.

I'm using the apiai-starter-app as the base, which functions perfectly fine until I add the line above which returns internal server error 500.

Note: I've tried before adding billing to the project and after as well. Neither work.

Edit: using this

        const https = require('https');

https.get('https://broker.bronos.net/v1/CLIENT_ID/ROOM_NAME/ACTION/PARAM', (resp) => {
  let data = '';

  // A chunk of data has been recieved.
  resp.on('data', (chunk) => {
    data += chunk;
  });

  // The whole response has been received. Print out the result.
  resp.on('end', () => {
            if (requestSource === googleAssistantRequest) {
        sendGoogleResponse(JSON.parse(data).explanation); // Send simple response to user
      } else {
        sendResponse(JSON.parse(data).explanation); // Send simple response to user
      }
  });

}).on("error", (err) => {
                if (requestSource === googleAssistantRequest) {
        sendResponse("Error: " + err.message); // Send simple response to user
      } else {
        sendResponse("Error: " + err.message); // Send simple response to user
      }
});

1 Answers1

0

Firebase's functions have limited access to external APIs on the free tier. By upgrading to Blaze or Flame plans you will be able to make external API calls.

Enabling Firebase Blaze plan + the following code worked

        const https = require('https');

https.get('https://broker.bronos.net/v1/CLIENT_ID/Living%20Room/volume/20', (resp) => {
  let data = '';

  // A chunk of data has been recieved.
  resp.on('data', (chunk) => {
    data += chunk;
  });

  // The whole response has been received. Print out the result.
  resp.on('end', () => {
            if (requestSource === googleAssistantRequest) {
        sendGoogleResponse(JSON.parse(data).explanation); // Send simple response to user
      } else {
        sendResponse(JSON.parse(data).explanation); // Send simple response to user
      }
  });

}).on("error", (err) => {
                if (requestSource === googleAssistantRequest) {
        sendResponse("Error: " + err.message); // Send simple response to user
      } else {
        sendResponse("Error: " + err.message); // Send simple response to user
      }
});
Nick Felker
  • 11,536
  • 1
  • 21
  • 35
  • I guess I'll try again, but just like I stated at the end, I tried with the blaze plan and without. Didn't seem to work. – Apathy Yhtapa Nov 13 '17 at 20:48
  • I had to fix my code on top of it. I marked you as the correct answer since technically speaking if my code had been correct that would've been my issue. – Apathy Yhtapa Nov 13 '17 at 20:53