3

I'm trying to get my Cloud Functions for Firebase to call a simple web app deployed using Google Apps Script. Can someone please point to any example or help figure out whats the reason for the error in my code below. Really appreciate your help.

--

I've created a simple webapp with Google Apps Script.

function doGet() {
   return ContentService.createTextOutput('Hello world');
}

And I'm calling this using request-promise within my Firebase Cloud Function. I've tried to be as close to the Google Translate example given for Cloud Functions. However, I get the following error when the Cloud Function is invoked.

RequestError: Error: getaddrinfo ENOTFOUND script.google.com 
script.google.com:443

Here is my Cloud Function code -

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const request = require('request-promise');

exports.makeUppercase = 
functions.database.ref('/users/{userid}/logs/{logid}/mykey')
.onWrite(event => {

  var url = `https://script.google.com/macros/s/.../exec`;
  var retstr = request(url, {resolveWithFullResponse: true}).then(
  response => {
    if (response.statusCode === 200) {
      const data = response.body;
      return event.data.ref.parent.child('uppercase').set(data);
    }
    throw response.body;
  });
});

Thanks in advance,

Regards Rahul

AL.
  • 33,241
  • 9
  • 119
  • 257
krahul
  • 51
  • 3

1 Answers1

0

I had the same issue and found this answer(https://stackoverflow.com/a/42775841). Seems like calling Google Apps Script is considered external.

akuroda
  • 17
  • 2
  • Greetings, this is not a definitive answer, it is a probable. The question should be flagged as a duplicate of the proposed link. – Nic3500 Nov 05 '17 at 02:07
  • 1
    I contacted to firebase support and got reply: If you are on a free tier (Spark plan), then this issue is an intended behavior as calling outbound network request is a limitation for this plan. Currently, Google Apps Script isn't on the supported services list for Cloud Functions, so the only way access it for now is to upgrade to a paid plan, see pricing page for more information. – akuroda Nov 05 '17 at 13:16
  • 1
    If you are on a Spark plan, you can use the Apps Script APIs to call a GAS function. It's more difficult (you need to deploy the GAS as API executable, you need user authentication to use Apps Script APIs, etc) but doable. I made an example here: https://gist.github.com/dan1wang/baf25ff2a45e6c53880e89185b0f29da – daniel May 31 '18 at 16:14