[SOLVED] Webhooks & Heroku

I’ve been playing around with Spark’s webhooks and successfully set up a hook and response on a local server.

I then tried to set up an application on Heroku which responds to the webhook and triggers a push notification, but with no luck. If I visit the Heroku app via my browser, it works as it should (push notif is received). It therefore seems to be a challenge with the headers sent by the Spark webhook (or lack hereof), though I’m not a 100% sure about this.

Therefore I wanted to hear if anyone has experience with Spark’s webhooks and Heroku, and/or other services like Heroku that work using webhooks.

Thanks.

Have you searched the forum for “Heroku” and read the threads already?

Yes, though none of them seem to cover webhooks, but instead connecting to Heroku through TCP and ensuring headers are sent when connecting. The difference is that I’m not able to edit (afaik) webhooks other than eventName and url. Therefore I was wondering if anyone had played with it before and found a solution.

In this case you could directly tag @harrisonhjones and @Dave who seem to have the best insight here :wink:

1 Like

Hi @Thomasoc,

In the webhooks beta invite, I include a note to try spark webhook create, which gives you this:

    Optional JSON Template:
    {
      "eventName": "my-event",
      "url": "https://my-website.com/fancy_things.php",
      "coreID": "optionally filter by providing a core id",
      "_": "The following parameters are optional",
      "requestType": "POST",
      "headers": null,
      "query": null,
      "json": null,
      "auth": null,
      "mydevices": true
    }

You can edit that file and any of those properties, to include a special header, you might write:

    {
      "eventName": "my-event",
      "url": "https://my-website.com/fancy_things.php",
      "requestType": "POST",
      "headers": {
         "Authorization":  "my-secret-header"
       }
    }

Or to send a body param as JSON you might add:

    {
      "eventName": "my-event",
      "url": "https://my-website.com/fancy_things.php",
      "requestType": "POST",
      "json": {
         "special_data":  "make-magic"
       }
    }

Then create the hook with:

spark webhook create somefile.json

Sorry the documentation is lacking, that’s the last thing to finish before we release it! :slight_smile:

Thanks,
David

1 Like

Thank you so much for your answer Dave - I should’ve noticed that during setup.

Though when I try to create a .json hook with
spark webhook create somefile.json it returns
Please specify an event name

Thanks a lot for your help.
Thomas

Hi @Thomasoc,

Hmm, what version of the CLI are you using? spark --version, I think the latest is 0.4.94, can you update? npm update -g spark-cli

Thanks,
David

Hi @dave. Thanks for the quick reply.

Thought that might be the problem, so updated earlier it when trying spark webhook create somefile.json. No luck.

Just to be sure: spark --version returns 0.4.94.

Hi @Thomasoc,

Did you actually create a file in that directory named “somefile.json” with your settings?

Thanks,
David

Thank you so much @Dave

For some reason I imagined it creating a .json file dynamically from the terminal. Works like a charm.

For future reference: Make sure to create the .json file in the local directory where you execute the spark webhook create somefile.json command.

While experimenting I noticed that Heroku requires a requestType GET instead of POST, see my working example below

Sending webhook request  { uri: 'https://api.spark.io/v1/webhooks',
  method: 'POST',
  json: true,
  form:
   { event: 'My-Event',
     url: 'https://xxxx.herokuapp.com',
     deviceid: 'XXXXXXXXX',
     access_token: 'XXXXXXXXXXX',
     requestType: 'GET',
     headers:
      { 'Content-Type': 'application/json',
        Accept: 'application/json' },
     json: null,
     query: null,
     auth: null,
     mydevices: true }}`
3 Likes

Hi @Dave

Can I please have an invite to the webhook beta? :slight_smile:

Thanks,
Sam

@Dave Me too?

Hi All!

I’m sorry about the very slow response! I’ve been working on releasing webhooks for the last few weeks, and we had a very soft / quiet launch this last week! We’ll announce it more fully tomorrow. :slight_smile: Enjoy!

http://docs.spark.io/webhooks/

Thanks,
David

2 Likes