New Feature! Webhooks!

Hello everyone.

I’m trying to create webhook since 3 days. But i can’t reach anything.

Firstly i have created a text file named with login.json which contains json data on Desktop, and run cmd window. I run command in terminal then i have changed my file directory to Desktop with cd Desktop command. After that i run command which is particle webhook create login.json. But i got a message Please specify an event name. What’s wrong with?

1 Like

Would you mind posting the contents of the JSON file? That should make it easier to spot any potential issues.

Yes. but i can’t create webhook from text file.

Which is why I’m asking you to post the contents of that file here :wink:

1 Like

I want to post JSON file

At this point I think it would be a wise decision to go over the documentation once more, and try do execute the example in there. That should give you a basic idea of what you’re supposed to be doing.
This is also a good topic to get going with webhooks relatively easy:

Ok thanks for your reply. I can create JSON file. And i must get response from post. How can i get it?

Again, this is mentioned in the docs: http://docs.particle.io/photon/webhooks/#handling-web-responses please do take a look, and read the whole page. That should give you more insight as to what’s going on.
There are also quite a few topics about this on the forum. Please try the search functionality, and I’m sure multiple topics will pop up. Here’s a useful one to get you started:
Cloud JSON Parsing

1 Like

Hi @emrebekar67,

He’s asking you to copy-paste the file into this thread on the forums, so we can see what configuration you’re specifying for the hook, and so we can fix any errors.

Thanks,
David

3 Likes

I have created a json file at below.

{
    "eventName": "rest_login2",
    "url": "https://login.salesforce.com/services/Soap/u/33.0",
    "requestType": "POST",
	"headers": {
		"Content-Type":	"text/xml; charset=UTF-8",
		"SOAPAction": "login",
		"Accept": "text/xml"
	}	
}

request type is shown as undefined. What is wrong?

Using settings from the file emre.json
Sending webhook request { uri: ‘https://api.particle.io/v1/webhooks’,
method: ‘POST’,
json: true,
form:
{ eventName: ‘rest_login2’,
url: ‘https://login.salesforce.com/services/Soap/u/33.0’,
requestType: undefined,
headers:
{ ‘Content-Type’: ‘text/xml; charset=UTF-8’,
SOAPAction: ‘login’,
Accept: ‘text/xml’ },
event: ‘rest_login2’,
deviceid: undefined,
access_token: ‘ecb70f15232ea2e6c99dc6022b47678168760235’ } }
Successfully created webhook!

Hi @emrebekar67,

Looks like the CLI might not be behaving quite correctly here. I just opened up a bug for this here:

Thanks,
David

Hi @hoxworth,

Good question! A few people have asked for this feature since we
launched, and it’s interesting, I think I can make it work. I’ll add it to my backlog and build it when I get a chance.

Thanks!
David

Hi @Dave, have you had a chance to look at this feature yet? I’ve been full steam ahead on a datalogger but ran into this wall. I’m trying to record voltage, current, and temperature from a project and log it to a database (then plotting it using highcharts). Any way you can think of to accomplish this? I could create multiple webhooks, one for each piece of data but it will be hard to line up the data for review.

Thanks!
-Jim

I’m planning on doing something similar using Node.js/MongoDB. I found that using JSON structured SSEs work pretty well. I stores my data to mongoDB after which I can graph it using HighCharts. I’d imagine that using Variables would work similarly, although that’d be a polling precess. Just an idea though :smile:

1 Like

Is there any way to subscribe to all events? When I leave event empty it is rejected with Please specify an event name.
I would like to be able to subscribe to “device came online”. Is this possible?

cc: @Dave

Have you tried subscribing to spark/status?
It won’t give you all, but I think it will give you the “device came online”

2 Likes

That’s restricted for very special accounts! If you’re a product owner you can see all events for your products. But yeah subscribing to “spark” or something would do the trick for your devices.

edit: if you were watching the public firehose, you’d blow through your rate limit in just a few milliseconds.

Thanks,
David

1 Like

@ScruffR @Dave Thanks a lot! That did the trick :smile:

1 Like

I am using webhooks to post a login id and password to a web app. The web app responds with an access token that I can subscribe to using:

Particle.subscribe(“hook-response/get_token”, gotToken, MY_DEVICES);

The web app handles its own user logins and accepts data that is tied to individually logged-in users via this access token.
In the Photon, after receiving this token, I use that token in the subsequent posts to that web app. The posted data is then tied to user that requested the token. I might have hundreds of different Photon devices logging in to the web app via my “get_token” webhook, each using unique login credentials. However, I want each individual device to see the specific hook response generated by its “get_token” call.

As I understand it now, all of my devices that are subscribing via:
Particle.subscribe(“hook-response/get_token”, gotToken, MY_DEVICES);
will be subscribing to their own as well as the responses intended for all other devices. I do not want all devices to see the responses generated by other publish calls from other devices.

Am I correct here?
Is there any way that a webhook subscription callback can be limited to responses generated by the specific device’s publications?

2 Likes

By the way, I found the answer to my own question.

From the documentation:
“You can also set the topic the webhook will use to help your devices filter and subscribe to the appropriate response! If you have a hook that services hundreds of devices, you can, for example include the device id in the topic, and have your device subscribe to events that only apply to it:”

1 Like

Could there be a feature to create a new Webhook by cloning an existing one?
It’s kind of tiresome to have to re-create the Webhook every time there is a minor change.

4 Likes