syncano

How do I pass in a payload to a Syncano webhook in Node.js?


I'm looking to use a private webhook in Node.js, however I'd like to pass in a few bits of data along with the webhook itself. How would I do this? The code in the docs without any payload looks like so:

var Syncano = require('syncano'); //CommonJS
var account = new Syncano({accountKey: "ACCOUNT_KEY"});

account.instance('INSTANCE_NAME').webhook('WEBHOOK_NAME').run(callback());

Where would I add in my payload to that request?


Solution

  • The run function is based on the parameter request, and you would pass in parameters this way:

    account.instance('INSTANCE_NAME').webhook('WEBHOOK_NAME').run({test: 'test'}, callback());
    

    If you are using this in the application code, do know that using the accountKey is highly insecure, and not a recommended method.

    Webhooks can be made public, and are callable by any typical XMLHttpRequest from the browser. You would pass parameters as you would any other POST request. For example, using jQuery would look something like this:

    $.post( "webhook url", {test: 'test'}, function(data) {
      console.log(data);
    });