Been attempting to set-up a webhook in Google Sheets Apps Script that will respond when changes are made in Trello. To do this, it's suggested to deploy the script as a web app (requiring doGet
and doPost
functions that return HTML) to create a URL destination for receiving post
and get
requests.
The web app makes two URLs, one ends in /dev
and is for development purposes (doesn't respond to post
requests) and the other ends in /exec
for normal access.
I've deployed the web app, both URL's are accessible and responsive in my browser (can view exec in incognito without sign-in), app is published to execute as "me" and be accessible by "anyone, even anonymous."
I have been able to successfully use the below code to create web-hooks for the /dev
URL but not the /exec
URL.
function create() {
var url = 'https://api.trello.com/1/tokens/ae6ebe60b45abcd2d4aa945c9ab4c4571bd6b6f7856b1df0cd387fbffc649579/webhooks/?key=a211f4aca7fb3e521d652730dd231cb6'
var payload = {
"key": "xxxxxxxxxxx",
"token" : "xxxxxxxxxxxxx",
"callbackURL": "https://script.google.com/macros/s/AKfycbw51TYGWHe95hKdcAs4l7E2eg0AtBi8e48lf_iafKYI/dev",
"idModel":"xxxxxxxx",
"description": "GW Test"
}
var options = {"method" : "post",
"payload" : payload,
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(url,options);
}
When using the /dev
URL, I can see that a new web-hook is added in my Trello, but the /exec
URL returns the following error:
{"message":"URL (https://script.google.com/macros/s/AKfycbxo90ucgXXz7MG6Z3wb2KD-PJn3akGKoelXLJ2mkg/exec) did not return 200 status code, got 403","error":"ERROR"}
So Trello was expecting a "200 Status Code" returned to verify that the script ran properly, but received 403 instead. What confuses me is why this doesn't happen when using /dev
? How can I get it to accept my /exec
URL?
More Info:
I can get my code to respond to put
and get
requests when I use link or load the URL directly in my browser. It responds by filling the first six (6) cells in the spreadsheet.
I have republished as a new version and verified that the code still works, but I still get the error message from Trello saying that they received a 403 rather than 200 code. And I only receive this error when using /exec
not /dev
. And since /dev
can't receive post
requests, it isn't going to be helpful :(
Below is the remainder of an example:
function doSomething() {
var values = [11,12];
SpreadsheetApp.getActiveSheet().getRange("A1:B1").setValue(values);
}
function create() {
var url = 'https://api.trello.com/1/tokens/ae6ebe60b45abcd2d4aa945c9ab4c4571bd6b6f7856b1df0cd387fbffc649579/webhooks/?key=a211f4aca7fb3e521d652730dd231cb6'
var payload = {
"key": "xxxxxxxxxxxxxxxxxx",
"token" : "xxxxxxxxxxxxxxxxxxx": "https://script.google.com/macros/s/AKfycbw51TYGWHe95hKdcAs4l7E2eg0AtBi8e48lf_iafKYI/dev",
"idModel":"xxxxxxxxxxxxxxxxxxxxxxxx",
"description": "GW Test"
}
var options = {"method" : "delete",
"payload" : payload,
// "muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(url,options); // creates webhook
}
// function that fires when the webapp receives a GET request
function doGet(e) {
doSomething();
var values = [21,22];
SpreadsheetApp.getActiveSheet().getRange("A2:B2").setValue(values);
return HtmlService.createHtmlOutput("something Get-ed");
}
function doPost(e) {
doSomething();
var values = [31,32];
SpreadsheetApp.getActiveSheet().getRange("A3:B3").setValue(values);
return ContentService.createTextOutput("something Posted");
//var params = JSON.stringify(e);
}
/dev
works. But the endpoint of/exec
doesn't work. From such situation, I thought that the latest script might not be reflected to Web Apps. So how about redeploying Web Apps as new version? By this, please test it again. If this was not the direct solution of your issue, I apologize. If this didn't work, can you provide a script of Web Apps?put
andget
requests when I use link or load the URL directly in my browser. It responds by filling the first six (6) cells in the spreadsheet. I have republished as a new version and verified that the code still works, but I still get the error message from Trello saying that they received a 403 rather than 200 code. And I only receive this error when using/exec
not/dev
. And since/dev
can't receivepost
requests, it isn't going to be helpful :(