Sending floats with the Particle Webhook

Hi All,

I’ve happily developed a webhook which sends data via HTTP POST, it looks something like this (excerpt from webhook, not full json!):

"json": {
    "uuid": "{{u}}",
    "type": "{{ty}}",
	"init": 0,
	"name":"{{n}}",
	"location":"{{lo}}",
	"status":{{st}},
	"timeStamp":"{{ti}}"
},

The ‘init’ fields seems to validate ok in the Particle webhook builder, but it does not like my ‘status’ field. Originally I was sending the ‘status’ field as a string i.e. “status”: “{{st}}” but I now want to send it in it’s true form: a floating point number - how do I do this?

Thanks
Joe

EDIT: As it stands, I get a ‘status’ field that looks like this:

{
.
.
"status" : "3.14",
.
.
}

But I am after:

{
.
.
"status" : 3.14,
.
.
}
1 Like

It cannot currently be done.

The reason is that the JSON template itself must be valid JSON. That’s not, because {{st}} is not a valid number. Sure, it may be a valid number when the template is resolved, but the template itself is not valid JSON, and it must be.

A feature will be added to webhooks in the future to allow a mustache variable to specify a type. This would allow the type to be set as a float, int, boolean, JSON object, etc. as necessary.

2 Likes

@rickkas7 thanks for the response - that’s a terrible shame!

1 Like

This issue, and the inability to use an Array as a root JSON object for requests (ex: "json": [{}] ), are blocking the ability to push weather station data to OpenWeatherMap API 3.0 with Webhooks. Any idea if/when this feature will be available?

I have the same issue. I really would like to push true numbers from mustache variables. This is a feature that would really fuel the IoT abilities… The alternative seems to be a buggy https library on the photon POST’ing directly to firebase.
Ping to @rickkas7

You can send true numbers (integer and float), as well as arrays, using the body definition for a webhook. It’s described here in the “using the body definition” section.

3 Likes

@NielsClausen - I just completed a port of a TLS library that should connect to https. It is in raw form so you will have to send the header/body and parse the server response. Please see this post.

1 Like

After reading and re-reading the docs and the tutorials, I am hoping I missed something. My current understanding is that we STILL can’t make product webhooks with the CLI and we STILL can’t use the body JSON to send numbers with the console. That means we can’t get a product to send numbers!?

Please tell me I am wrong.
This is holding up commercialization of a product and may, in fact, kill it.

You can create a true number using the body definition, two posts above. (You can’t using the “json” key but you can using the “body” key.)

You currently cannot create a product webhook using the CLI, but here’s a script that will do it:

Rick

Thanks!
I worked through your notes and script for the last few hours. I was having trouble formatting the JSON file correctly for use with your script. I finally figured out it doesn’t like spaces, tabs or new lines in the body along with escaped double quotes, so easy-to-read JSON formatting broke it. I fixed it by altering your script to remove the white space. FWIW, I couldn’t get JSON.minify or other methods to work with the escaped double quotes.

var hookStr = fs.readFileSync(argv._[1], 'utf8');
hookStr = hookStr.replace(/\r?\n|\r/g, "");
hookStr = hookStr.replace(/\t/g,""); 

{
“event”: “CoolEvent”,
“url”:“https://requestb.in/t1s2tdt1”,
“requestType”: “POST”,
“query”: { “api_key”:“nothing”},
“headers”: {
“content-type”: “application/json”
},
“body”: “{ //JSON.parse would break here, giving a SyntaxError
"feed”:{
“component”:[
{
“componentId”:"{{PARTICLE_DEVICE_ID}}",