Webhook to Google Sheet from Trello

290 Views Asked by At

I want to connect webhook to google sheet via google apps script. Previously, it helped to set up the deployment of a web application for everyone runing and the webhook was connected. Now throws an error.

{
    "message": "URL (https://script.google.com/macros/s/.../exec) did not return 200 status code, got 302",
    "error": "VALIDATOR_URL_RETURNED_ERROR"
}

Code to connect i use before:

let webAppUrl = "https://script.google.com/macros/s/.../exec";
let spreadSheetId = "...";

let trelloKey = "...";
let trelloToken = "...";

let trelloBoard = "..."; //  Board

function setWebhookTrello() {
  let data = {
    'key': trelloKey,
    'token': trelloToken,
    'callbackURL': webAppUrl,
    'idModel': trelloBoard,
  };

    const params = {
    'method': 'POST',
    'contentType': 'application/json',
    'payload': JSON.stringify(data)
  }
UrlFetchApp.fetch('https://api.trello.com/1/webhooks?', params);
}

When i try to connect webhook with another URL (like https://webhook.site/) - working correct

I see this - How to create webhook from Google Apps Script using the "exec" url rather than "dev" url. Exec returns 403 Error but now it dont work =(

1

There are 1 best solutions below

0
spikeston On

I experienced the exact same issue. The only workaround I came up with was to make a simple Google Cloud Function "relay" that receives the POST request and returns a 200 response, then passes that request body to the Google Apps Script web app. Here is an example of the GCF:

const functions = require('@google-cloud/functions-framework');
const axios = require('axios');

functions.http('entryPoint', (req, res) => {

  const url = 'https://script.google.com/macros/s/YOUR_WEB_APP_ID/exec';
  const data = JSON.stringify(req.body);

  axios.post(url, data)
    .then((response) => {
      console.log(JSON.stringify(response.data));
      res.send(`200 OK`)
    })
    .catch((error) => {
      console.log(error);
    });

});