JohnHMr
JohnHMr

Reputation: 11

Apps script doGet(e) not firing when URLfetch from another apps script project

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.

Upvotes: 0

Views: 936

Answers (1)

TheMaster
TheMaster

Reputation: 50453

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!

Upvotes: 1

Related Questions