0

I used Directory API push notifications example of https://stackoverflow.com/users/6586255/dimu-designs from this question: Is it possible to watch Directory API changes from Google App Maker/Google Apps Script?

I have two projects setup, another one is webhook itself:

    /** HTTP GET request handler */
function doGet(e) {
    return ContentService.createTextOutput("GET message");
}

/** HTTP POST request handler */
function doPost(e) {
    return ContentService.createTextOutput("POST message");
}

And other one is the watch request:

function startUpdateWatch() {
    var channel = AdminDirectory.newChannel(),
        receivingURL = "https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/exec",
        gSuiteDomain = "[business-name].com",
        event = "update";

    channel.id = Utilities.getUuid();
    channel.type = "web_hook";
    channel.address = receivingURL + "?domain=" + gSuiteDomain + "&event=" + event;
    channel.expiration = Date.now() + 21600000; // max of 6 hours in the future; Note: watch must be renew before expiration to keep sending notifications

    AdminDirectory.Users.watch(
        channel, 
        {
            "domain":gSuiteDomain,
            "event":event
        }
    );
}

Webhook url works fine, it fires "Get" when I try to open it via browser. startUpdateWatch function starts fine as well without errors and if I try to change the url to something else, I get an error, so that receiving url should be ok as well.

How you debug that push channel? I have tried to launch function with different events like 'add' and 'delete' as well and then deleted/added/modified user in G suite, but no push from that function towards the url.

  • 1
    Use [StackDriver Logging](https://developers.google.com/apps-script/guides/logging#stackdriver_logging) along with a tool like [Postman](https://www.getpostman.com/) to make and debug your **POST** Requests. – TheAddonDepot Feb 28 '19 at 11:20
  • Will try this. Thanks for the tip! – Lazy Warthog Feb 28 '19 at 12:57
  • Hmm.. "If the watch request successfully creates a notification channel, it returns an HTTP 200 OK status code." It sends this to webhook? How to catch this one? – Lazy Warthog Mar 07 '19 at 15:41
  • Oh, sorry.. it already handles push and get, so apparently it doesn't send anything. – Lazy Warthog Mar 07 '19 at 15:42

0 Answers0