I have been trying to Receive a shopify webhook to my trellinator google app script. In my research I have found out that my code should run on doPost function and then send a 200 OK response.
I have performed some tests and my code is running fine, but the webhook keeps triggering as if it did not received the 200 OK response.
I know that trellinator uses doPost function to execute some code, and I do not know how to receive my webhook on top of trellinator platform.
Below you can find the doPost function I am taltking about
function doPost(e)
{
var hooks = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Custom Webhooks");
var htmlOut = false;
//Here is were I execute my function
myFunction(e);
//My function ends
if(hooks)
{
new IterableCollection(hooks.getDataRange().getValues()).each(function(row)
{
if(this[row[0].trim()] &&(htmlOut === false))
{
htmlOut = this[row[0].trim()](e);
}
});
}
if(htmlOut === false)
{
if(e.postData)
{
var notifText = e.postData.contents;
var htmlOut = doPosting(notifText);
}
else
{
var htmlOut = HtmlService.createHtmlOutput("<p>Processed Notification</p>");
}
}
else
{
var htmlOut = HtmlService.createHtmlOutput("<p>Processed Notification</p>");
flushInfoBuffer();
}
return htmlOut;
}
@Carlos Pozos Ochoa I'll reply here as well as in Reddit :)
Note that you shouldn't ever need to edit any of the Trellinator files.
This is an undocumented feature, but just create a sheet in your Trellinator spreadsheet called "Custom Webhooks" then put your function names in the first column, no header column. So in your case you would just enter
myFunction
into cell A1.
These functions will be called before the Trellinator notification processor, if you return "true" from your function, processing will stop, that is the notification will not proceed to be passed into your Trellinator functions.
If you return "false" then the notification will be passed onto your Trellinator functions. So an example of a custom webhook might be something like this:
https://gist.github.com/iaindooley/c344cc62c08858736ce18e8cf920c44e
Thank you Iain, I have tested the code you propose and it is executed right. The problem is that I should reply shopify in a 5 second window with the 200 OK response, but looking at my logs "myFunction" is taking longer than that time to reply, so the webhook is firing continously. Is there anyway I can add my function to your trellinator queue? So this way I can anwer inmediately to shopify and let my funciton execute later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Carlos Pozos Ochoa yep just use the same URL that is set up for all your other boards. You can see by running this piece of code:
https://gist.github.com/iaindooley/ee64dd680d1991ede55aa5cb7ef843bd
just grab your token from the Configuration tab and put it in there. You can use that webhook directly the same as you would use the published script URL, it just queues the requests and forwards them onto the script anyway
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome, it worked perfectly. Thank you very much for all your work and the knowledge you share.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.