Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function triggerWebhook() {
- // Your N8N webhook URL
- const webhookUrl = "{PRODUCTION-WEBHOOK-ENDPOINT}";
- // Set up HTTP request options - just sending a simple trigger message
- const options = {
- method: 'post',
- contentType: 'application/json',
- payload: JSON.stringify({
- triggered: true,
- timestamp: new Date().toISOString()
- }),
- muteHttpExceptions: true
- };
- try {
- // Send the HTTP request
- const response = UrlFetchApp.fetch(webhookUrl, options);
- // Log the response
- Logger.log('Response code: ' + response.getResponseCode());
- Logger.log('Response body: ' + response.getContentText());
- // Show a success message to the user
- SpreadsheetApp.getActiveSpreadsheet().toast('Webhook successfully triggered!', 'Success', 5);
- } catch (error) {
- // Log and show any errors
- Logger.log('Error: ' + error.toString());
- SpreadsheetApp.getActiveSpreadsheet().toast('Error triggering webhook: ' + error.toString(), 'Error', 10);
- }
- }
- /**
- * Optional: Adds a custom menu to the Google Sheets UI
- * This allows users to trigger the webhook from the menu
- */
- function onOpen() {
- const ui = SpreadsheetApp.getUi();
- ui.createMenu('Webhook Tools')
- .addItem('Trigger N8N Webhook', 'triggerWebhook')
- .addToUi();
- }
Advertisement
Add Comment
Please, Sign In to add comment