问题
I want to Create a new API app usin Google Apps script and Hello sign API
I have specified the redirect URL as https://script.google.com/macros/s/AKfycbyKw3oLmpqINGsDml281iUbxBboKn950dqVFXNibMfLurxYcRPf/exec and the screenshot is shown below
Also, the code of the apps script file is
function doPost(e) {
return ContentService.createTextOutput("Hello API Event Received.");
}
The documentation says: https://app.hellosign.com/api/eventsAndCallbacksWalkthrough
I get error message as shown like here
Illustation image here
回答1:
Looking at our backend logs, we see that your callback URL is not allowing our POST call to be granted to fetch "Hello API Event Received" response. This can be due to they way your [callback handler is set up][1].
Would you mind taking a look at this similar ask and they way they tackled the POST/Allow
header field and let us know how it goes by emailing at apisupport@hellosign.com?
App Script sends 405 response when trying to send a POST request
[1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405#:~:text=The%20HyperText%20Transfer%20Protocol%20(HTTP,supported%20by%20the%20target%20resource.
回答2:
405
(http-status-code-405) is "method not allowed", where a incorrect method is used. In this case, ContentService uses a specific pattern of redirection (post-redirect-getwiki), where the POST
request to script.google.com
is redirected(302) to a one time url at script.googleusercontent.com
, to which a GET
request should be made.
302 specification did not intend the method to change from POST
to GET
, but this pattern is very common in the web. But, hellosign-api seems to make another POST
request to the one time redirected url at script.googleusercontent.com
. There isn't much you could do from apps script to change this behavior. It is possible to change to HtmlService
to avoid the redirection, but Hellosign specifically requires you to provide a specific text content as response: Hello API Event Received
. This isn't possible with HtmlService
.
You could make a feature request/bug fix request to Google to change redirect status to 303, where method change to GET
is explicitly specified. Or Make a request to Hellosign to follow 302 redirects with GET
request, as that is the most common way, things are done in the web.
References:
- Curl redirect preferred method -L
- ContentService Redirect
- Post redirect get wiki
- RFC7231 § 6.4.3
- RFC7231 § 6.4.4
来源:https://stackoverflow.com/questions/63674548/connecting-a-hello-sign-api-to-apps-script-project