-1

I need to send 2 pieces of information from 1 apps script project to another apps script project.

I created a web app with the doGet(e) function in it. when I paste this web app URL on the browser and {ENTER}, the doGet(e) fires, and I get the parameters (that I passed in) from the URL; works as planned.

URL(for ref): https://script.google.com/a/macros/s/AKffmPwm42Xg/exec?sku=YD304514Z&price=8.50

But now, when I try, on a different apps script project, to URLfetchapp.fetch('https://script.google.com/a/macros/s/AKffmPwm42Xg/exec?sku=YD304514Z&price=8.50'), my doGet(e) is not firing like it does when I paste and {ENTER} in the browser.

So, Brower → web app: doGet(e) fires!

Apps script URLfetch → web app: nothing happens..

doGet(e) on the web app apps script page:

function doGet(e) {
     let parms = e.parameter;
     let sku = parms[ 'sku' ];
     let price = parms[ 'price' ];
     doOtherStuf( sku, price); //the other function where I need the info
}

The script that I'm trying to send the info to the web app (note that these two scripts are in different apps script projects):

function foo() {
    let sku = 'D30451Z';
    let price = 8.50;
    let reqBD = `?sku=${sku}&price=${price}`;
    let link = `https://script.google.com/a/macros/s/AKffmPwm42Xg/exec${reqBD}`;

    let fet = URLfetchapp.fetch(link);
    Logger.log(fet.getResponseCode()); //outputs 200
}

Placing the web app link in the browser and {ENTER} works, but if I run the foo() function, it doesn't. I never get an execution on the execution page for the doGet(e). So, my question is more about how to get the foo() function right.

I also tried:

let fet = URLfetchapp.getRequest(link); //doesn't work
let fet = URLfetchapp.fetch('https://script.google.com/a/macros/s/AKffmPwm42Xg/exec?sku=YD304514Z&price=8.50'); //doesn't work

I deployed it as Web App.

Deploy → New Deployment:

type: Web App;

Execute as: Me

Who has access: Only me.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
JohnHMr
  • 1
  • 2
  • 1
    Did you deploy it on the second project? – Cooper Sep 20 '22 at 18:26
  • 1
    How is the webapp published? See [tag info page](https://stackoverflow.com/tags/google-apps-script/info) for information you need to provide about web apps, when asking a question – TheMaster Sep 20 '22 at 18:35
  • @Cooper Hey, thanks for the help. Yes, I deployed it as Web App. Deploy → New Deployment: type: Web App; Execute as: Me; Who has access: only me. It works when I use se URL directly on the browser. – JohnHMr Sep 20 '22 at 19:56
  • @TheMaster Hey, thanks for stopping by. Sorry, what do mean? I followed these steps for deplying it: Deploy → New Deployment: type: Web App; I'll give a read on the tag info page. Thanks! – JohnHMr Sep 20 '22 at 20:01
  • Second project won't automatically send your Google account credentials. You need oauth token with drive access scope. Search tag info page for Tanaike's webapp list – TheMaster Sep 20 '22 at 20:05
  • @TheMaster oooooh Thank you! There is nothing nowhere talking about this (I'm talking about sending stuff from **my account** to **my account**), not even in other related questions, I searched. Thanks again. – JohnHMr Sep 20 '22 at 21:52
  • See " Taking advantage of web app" in tag info page(my first link). It doesn't matter if it's your account to your account. Google doesn't know it's you, unless you provide the access token. – TheMaster Sep 20 '22 at 21:54

1 Answers1

0

The fix for this problem → where I'm sending stuff from my account to my account:

Deploy → New Deployment:

type: Web App;

Execute as: Me

Who has access: Anyone.←

With this modification in the "Who has access:" I was able to send the info that I needed, through the URL, by using URLfetchapp.fetch('URL'); The code is the exact same as the blocks of code on top. The only difference is in the "Who has access:" option.

I appreciate all the help given. Thank you!

TheMaster
  • 45,448
  • 6
  • 62
  • 85