I'm trying to create a Web App with a doPost()
method. This POST method should receive and answer the POST request from the Webhook with a Challenge, and receive the corresponding JSON that will be placed in a Google Sheet.
Current code looks something like this:
function doPost(e) {
// Try to answer the challenge
return ContentService.createTextOutput(JSON.parse(e.postData.contents).challenge);
// . . . do something else here with the JSON . . .
}
When I do the POST from Postman its returning this error:
{
"success": false,
"message": "Invalid callback challenge key returned",
"detail": "Expected '[Challenge_ID_Here]' but received '[Google HTML Code Here]'"
}
I set up a callback_url with https://webhook.site/ and got a successful response from it when setting it up with request.form.challenge
, but I don't know how to answer with the challenge correctly with the Web App.
I successfully got the doPost()
method to successfully parse the Challenge ID and print it in the Google Sheet.
I'm now trying to respond back with the ID like this:
return ContentService.createTextOutput(JSON.parse(result).parameters.challenge).setMimeType(ContentService.MimeType.JSON);
Still getting an unsuccessful response, but it is now redirecting to a script.googleusercontent.com
domain, saying that the file has moved there. I enabled following redirects in Postman.
My POST request from Postman looks something like this:
curl --location --request POST '[Webhook_Subscriptions_URL]' \
--header 'Authorization: Bearer [Token_ID]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'object=myObject' \
--data-urlencode 'fields=myField1, myField2' \
--data-urlencode 'callback_url=https://script.google.com/macros/s/[ID]/exec'