Search code examples
internal-server-erroractions-on-googlehttp-status-code-500

Communicating with an external service: internal server error 500


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
      }
});

Solution

  • 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
          }
    });