Webhooks & Parse.com

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