Trying to receive an SMS at my Twilio number and send a POST request to a Google Apps Script app URL as a result of the received SMS.
I have this doPost() message:
function doPost(request) {
return ContentService.createTextOutput("User says: "+JSON.stringify(request));
}
Some text should be spit out containing the request data.
My doPost() method never gets called. I can't tell if the POST request is actually being sent by Twilio. I see in the Twilio number message log that my SMS is received by Twilio. But after that I can't tell. I have the Twilio number configured for webhook - HTTP POST, and the published URL of my Google Apps Script project. If I change that to HTTP GET my doGet() method DOES get called. I need to doPost() method called, though. any suggestions? TIA.
How about the following confirmation?
Confirmation points :
Redeploy Web Apps as a new version again.
When the script is updated, Web Apps is required to be redeployed as a new version for reflecting the update.
Confirm setting for Web Apps.
"Execute the app as:" is "Me".
"Who has access to the app:" is "Anyone, even anonymous".
Retrieve a log of request using Stackdriver.
The sample script is as follows. Please copy and paste it. And redeploy Web Apps.
Request POST.
On script editor, click View -> Stackdriver Logging
By this, when POST request is received, you can see the log.
Sample script :
function doPost(request) {
console.log(JSON.stringify(request)); // Here
return ContentService.createTextOutput("User says: "+JSON.stringify(request));
}
By above confirmation, the reason of your problem may be found. But if this was not useful for you, I'm sorry.
I decided to just use doGet(). See my response to the previous comment.
Related
I'm currently using Apps Script to build a webpage. Is there a way to get the parameters in the URL without using doGet(e)? i.e. Can I use a getParams() function to retrieve the URL?
Answer
No, it is not possible
How Web-Apps work
When a user visits an app or a program sends the app an HTTP GET request, Apps Script runs the function doGet(e). When a program sends the app an HTTP POST request, Apps Script runs doPost(e) instead. In both cases, the e argument represents an event parameter that can contain information about any request parameters.
Ask for a feature request
Google has a tool called Issue Tracker that tracks bugs and feature requests during product development. You can open a new feature request there.
I'm attempting to make a post request from an Airtable script to Google Apps Script. I have a doPost() function set up in the Google Apps Script file, but the post request needs to be authenticated to run.
I believe I need to pass an OAuth token in the header of my request, but I'm unsure how to get this token in the first place. I've found this doc here about web apps in Google Apps Script but no luck finding how to generate an OAuth token from an external service.
I may be completely off the rails with my thinking, so if there's an easier way to make a post request and authenticate it from an external service, I'm all ears.
EDIT:
I don't really have any code at the moment. I'm using Postman to send the calls to Google to test. In Apps Script I have the following inside just to test.
doPost(e) { Logger.log("POST REQUEST") }
When I make the call from Postman, the function isn't triggered. In short, I know I need an authorization in the post request, but I don't know how or where to get it.
I'm new to this and trying to figure out the basics. I want to use google apps script to receive requests from slack and send back information from a spreadsheet.
I am stuck at this step. EventsAPI - URL Verification. My approach was to have a doPost() function that returns the challenge. After I was able to confirm slack could connect to the app I would be able to build it out to send the required information from the spreadsheet.
function doPost(e){
return ContentService.createTextOutput(JSON.parse(e.postData.contents).challenge);
}
I expect the challenge to be successfully returned and the URL verified.
The error I receive in Slack is Request URL Your URL didn't respond with the value of the challenge parameter.
I have a Google Apps script deployed as a Web Application, and then I have a web app. hosted at www.mjpanel.com, that calls the Google Apps script as a web service. In the www.mjpanel.com app, I synch. up with Google requesting the following scopes:
.init(
{
client_id: '[Client ID].apps.googleusercontent.com',
fetch_basic_profile: true,
scope: 'https://www.googleapis.com/auth/drive https://mail.google.com https://www.googleapis.com/auth/gmail.send'
}
);
This includes the request I can find for 'all gmail authorization'. When that call issues and the authorization box pops up telling them what my app. is requesting to do, one of the items is "Send Email On Your Behalf".
My Google Apps Script needs the permission to "Send Email As You", which is different than "Send Email On Your Behalf". Thus, when the app. reaches a point that it is going to issue a web service request to my Google Apps script that exercises the code to "Send Email As You", the web service call is failing due to the lack of permission. If I debug, capture the Google Apps script URL that the web service call is getting sent to, and paste into a browser tab, I get a return that is the button for the user to authorize my app. to "Send Email As You".
However, that is no good, because this is happening as a Web Service call.
What I need is a way to request the "Send Email As You" scope up front; but I can't find any documentation that tells me how to frame that scope request.
Thanks in advance for any help you can give me.
I believe the scope is https://www.googleapis.com/auth/script.send_mail.
To force a script to request that, you can write a commented use of MailApp e.g.
// MailApp.sendEmail();
It won't do anything but it will get detected by Apps Script which will prompt for authorization.
I have some technical question about using apps script.
A third party server is sending me parameters in POST method and the request looks like this: https://script.google.com/macros/s/AKfycbyJYVLO46T1LnQKktaMrROclCOqgawcVfZaRbm_oXfJaMIYcPj8/exec?value=$postback_params_test$ (so I need to receive $postback_params_test$ as value)
I used doPost(e) function but with no success, I thing the problem is because apps script is based on client java script and it c'ant talk with server language, am I right? or there is an option to do it anyway through apps script?
my code:
function doPost(e){
var param = e.parameter.value;
var doc = SpreadsheetApp.openById("106jpepwZZWXtpO4Id45qmJovV68q_DIqpEmTQ0khf4E");
var cell = doc.getRange('a1');
cell.setValue(param);
}
8.6
Image added:
enter image description here
When deployed as a web app with settings "execute as: me" and "who has access to the app: anyone, even anonymous" your example code works.
Did you authorize the code? Before you can run it as a web app, you must run doPost() (or another function) once manually from within the script editor, so you can grant the appropriate permissions to the script.
If it's not the authorization issue, you can add a MailApp.sendemail() call to help you troubleshoot.
function doPost(e) {
MailApp.sendEmail('YOUR-EMAIL HERE','TEST doPost()',JSON.stringify(e));
This way you'll receive an email showing the raw request coming from the other server.
Be sure to re-run the script manually after adding the MailApp line so you can authorize it to send email, and update the published version.