Webhooks & Parse.com

@Dave, could a flag in the webhook definition be added to indicate whether the webhook should send the extra data or not?

1 Like

Hi @peekay123,

Totally! I think that makes sense, just trying to get a feel for how to present that, how it should work, etc. :slight_smile:

Thanks!
David

3 Likes

@Dave please do :slight_smile: I wooden mind for example:

  • raw: true/false

ps. could you answer my 2 last questions? :slight_smile:

2 Likes

Hi @davidgatti,

Ah sorry, I missed those :slight_smile:

  • authentication, you can use the auth section if you want the hook to generate the header for you, or you can set it manually if you want. For basic auth I don’t think there is much of a difference, but once is slightly more convenient.

  • JSON - this really depends on what your site wants, if it wants a “form submit” type request, or a JSON body / payload. Most things now-a-days want JSON, but it really depends if your site is getting confused by the extra parameters, or by the headers being different from what it expects.

Thanks,
David

1 Like

@Dave sadly the post method doesn’t work for Parse.com.

If you decide to add the Raw flag, when do you think you will be able to release it?

Best.

1 Like

As a temporary fix i created a NodeJS Proxy. Anyone interested check my project here IoT Water Flow Meter. I hope it helps.

@davidgatti, I pinged @Dave for an update :smile:

1 Like

Sorry, still in the pipeline, I don’t have an estimate for this besides just “as soon as I get a chance,” sorry! Maybe today!?

Thanks,
David

Looks like this is done :slight_smile:

Yes! You can now set the “noDefaults” flag to true, and it’ll only include your request as defined without the extra params. :smile:

Thanks,
David

1 Like

Thanks @Dave

@dave maybe i’m misunderstanding noDefaults, when i set it to true it seems to leave the body blank when I hook it up to requestb.in, I expected the contents of my “json” parameter to show up in the body, is this not the case?

Hi @hawesg,

Sorry about the slow reply! “noDefaults” means it won’t add any default parameters to your request. You’ll still need to map json parameters from your publish into your webhook if that makes sense.

Thanks!
David

@dave, not really. I’ve tried a bunch of different things, no matter what I do noDefaults gives me a blank body. Could you post a basic example where you get data.

Upon closer inspection, I see what you mean! I think this is a bug, 1 moment.

Thanks,
David

Okay, give it a try now! Sorry about that!

Here’s my test case:

###requestbin.json

{
	"eventName": "some_event",
	"url": "http://requestb.in/xdbjumxd",
	"requestType": "POST",
	"query": { 
		"key": "{{value}}",		
		"coreid": "{{SPARK_CORE_ID}}"
	},
	"noDefaults": true,
	"mydevices": true
}

###test commands

particle webhook create requestbin.json
particle publish some_event "{\"value\":234234}"

Thanks,
David

Thanks so much @Dave I thought I was going nuts. To be fair I should have asked much sooner :slight_smile:

I was referred here from the following: Using Spark.publish() with Simple JSON Data

Unfortunately, I think that this is still an issue. I think the issue arrises when you have to specify application/json in the headers.

here is my json:

{
    "event": "segment",
    "url": "https://PASSWORD@api.segment.io/v1/track",
    "requestType": "POST",
    "headers": {"content-type": "application/json"},
    "json": {
        "published_at": "{{SPARK_PUBLISHED_AT}}",
        "userId": "{{SPARK_CORE_ID}}",
        "From" : "+1 747-225-8111",
        "To" : "+13107458875",
        "Body" : "{{SPARK_EVENT_VALUE}}"
    },
    "mydevices": true
}

Here is the data that Particle says that I am posting:

Here is the data my third party app interprets:

Notice “data”: appended to the event. obviously this is the default. If I alter my json to be:

{
    "event": "segment",
    "url": "https://PASSWORD@api.segment.io/v1/track",
    "requestType": "POST",
    "headers": {"content-type": "application/json"},
    "json": {
        "published_at": "{{SPARK_PUBLISHED_AT}}",
        "userId": "{{SPARK_CORE_ID}}",
        "From" : "+1 747-225-8111",
        "To" : "+13107458875",
        "Body" : "{{SPARK_EVENT_VALUE}}"
    },
    "noDefaults": true,
    "mydevices": true
}

(I added noDefaults) Particle still receives my event, but no event is passed to the third party.

I think this is two separate issues, it seems like the webhook is posting data as a string within “json”:{} which includes the 's and does not format the json properly on post, so the third party only receives one event. The other is an issue with noDefaults, which seems to stop any data from being passed.

Working on a similar setup - using webhook to post data to Parse.com using JSON, I have partial success :blush:

Success:
This is my webhook using which I want to store the value of a string variable in the Parse DB:

   {
	"eventName": "some_event_pt2",
	"url": "https://api.parse.com/1/classes/DataFromParticle",
	"requestType": "POST",
	"headers": {
        "X-Parse-Application-Id": "this is the parse app id",
        "X-Parse-REST-API-Key": "this is the rest api key",
        "Content-Type": "application/json"
    },
	"json": { 
		"stringData": "{{particle_string}}"
	},
	"noDefaults": true,
	"mydevices": true
}

Problem
However, when exactly the same code is run changing the string variable to an integer, it does not store the data in the Parse DB.

   {
	"eventName": "some_event_pt2",
	"url": "https://api.parse.com/1/classes/DataFromParticle",
	"requestType": "POST",
	"headers": {
        "X-Parse-Application-Id": "this is the parse app id",
        "X-Parse-REST-API-Key": "this is the rest api key",
        "Content-Type": "application/json"
    },
	"json": { 
		"integerData": "{{particle_integer}}"
	},
	"noDefaults": true,
	"mydevices": true
}

I suspect the reason is because when the Particle webhook sends the data the integer value is enclosed in quotes (checked using requestb.in). It works if the value in the integerData is hard-coded as:

		"integerData": 123456

Question: (@dave)
How can the webhook handling be modified to prevent enclosing the integer variable value in quotes?
This doesn’t work:

"integerData": {{particle_integer}}
1 Like

@pteja integer or other decimal variables are not supported by web hooks, yet.
I run into the same problem:

2 Likes