Webhhooks: Custom JSON Script still adds adds 'default attributes' and not all json is being sent

My webhook still send out the default data (ie ttl, coreId, PublishedAt, name) although I am creating a custom webhook as per WebHook with more then one value

This shows up on the webhook, although I gave no indication for the default attributes to be set:

This is the JSON I am using in the webhook, would sending incorrect json data from Particle.publish() stop the ‘variable forwarding’ function from within the Particle webhook system from working?

Webhook json:

 {
        "eventName": "RequestBinTest",
        "url": "[URL HERE]",
        "requestType": "POST",
        "json": {
            "type": "{{type}}",
            "uuid": "{{uuid}}",
            "name": "{{name}}",
            "systemID": "{{systemID}}",
            "deviceType": "{{deviceType}}",
            "location": "{{location}}",
            "timeStamp": "{{timeStamp}}"
        },
        "nodefaults": true,
        "mydevices": true
    }

Data being sent from the Particle:

String publishString = "{\"type\":" + type + ", \"uuid\":" + uuid + ", \"name\":" + name + ", \"systemID\":" + sysID + ", \"deviceType\":" + deviceType + ", \"location\":" + location + ", \"timeStamp\":" + tStamp + "}";

All variables are being wrapped with quotation marks using \" ie String variable = "\"text\"";
Any ideas what I am doing wrong?

Edit: I’ve noticed the full json (contained within publishString) isn’t being sent, rather it is ‘cut off’ at a point.

I think the problem is that in the webhook custom JSON noDefaults is case-sensitive and has a capital D.

1 Like

Oh brilliant, that fixed it! Any idea why my json field are empty?

{"timeStamp":"","location":"","deviceType":"","systemID":"","name":"","uuid":"","type":""}

I take it I’m doing something wrong when passing the variables? All of the names of the variables match the webhook json and I’ve built the string correctly (publishString)

@Dave @rickkas7 could you help out? The story so far:

I’ve set up a Requestbin to test the system. The Particle webhook uses this json:

    {
        "eventName": "RequestBinTest",
        "url": "URL here",
        "requestType": "POST",
        "json": {
            "type": "{{type}}",
            "uuid": "{{uuid}}",
            "name": "{{name}}",
            "systemID": "{{sysID}}",
            "deviceSubType": "{{deviceSubType}}",
            "location": "{{location}}",
            "timeStamp": "{{tStamp}}"
        },
        "noDefaults": true,
        "mydevices": true
    }

I’m hoping to pass all of this data using Particle.publish() on the Electron, code snippets below:

    String type = "\"Alarm\"";
    String uuid;
    String name = "\"Test alert\"";
    String sysID = "\"TestsysID\"";
    String deviceSubType = "\"Notification\"";
    String location = "\"Global\"";
    String tStamp = "\"00-00-0000\""; //need to change this later 
    String buff(key.returnUUID()); //generates a uuid
      uuid = "\"" + buff + "\""; //adds ""
    
    String publishString = "{\"type\":" + type + ", \"uuid\":" + uuid + ", \"name\":" + name + ", \"systemID\":" + sysID + ", \"deviceSubType\":" + deviceSubType + ", \"location\":" + location + ", \"timeStamp\":" + tStamp + "}";
      
      //Serial.println(publishString);
      Particle.publish("RequestBinTest", publishString, PRIVATE)

The particle sends data to the particle cloud fine, except that my json string (ie what is contained within publishString) is cut short. Here is an image that shows the sequence working correctly: data sent up>hook-sent>reply from RequestBin

;
(Clicking for more information shows my json is cut short ie:

Also, I have set noDefaults ‘True’, yet I am still seeing ttl, coreId etc after my cut off json!

I get a blank set of fields with no data, when looking in requestBin. I’m fairly certain this is because the json being sent up is being cut short, therefore it is not recognised as json.

Help!

I don’t see anything obviously wrong. It doesn’t look like you’re hitting the 255 byte publish string length limit, or at least that’s not where it’s cut off.

I’d start by first making publishString a single string, entered by hand, and see if that works to try to isolate the problem.

If the JSON being sent in the Particle publish is invalid (such as cut off) then the web hook will behave in sometimes unexpected ways. I think it’s falling back to some default settings because the data can’t be parsed as valid JSON, so once you fix the data input problem, the noDefaults problem should also go away so I wouldn’t worry about that until you get the first part fixed.

Thanks for the confirmation. I’ll give that a go now!

Oh, wait, I did miss something. You’re not quoting any of the values. It should look more like this (not positive I pasted all of the quotes in the right places).

String publishString = "{\"type\":\"" + type + "\", \"uuid\":\"" + uuid + "\", \"name\":\"" + name + "\", \"systemID\":\"" + sysID + "\", \"deviceSubType\":\"" + deviceSubType + "\", \"location\":\"" + location + "\", \"timeStamp\":\"" + tStamp + "\"}";

They are quoted in the declarations ie

String type = "\"Alarm\"";

@rickkas7 want to see something strange? I have the json string print to serial before being sent off…

In the terminal:

 {"type" : "alarm", "uuid" : "012345-ab458-2fdfg", "name" : "test alert", "systemID" : "testSys","deviceSubType" : "notification", "location" : "global", "timeStamp" : "00-00-000"}

Which is what I expect…

But the data I get from the dashboard log:

It has cut off the end of my string again! Completely at a loss now! :smile:

(also, I tried this with a single field with another RequestBin, and it worked fine (except the default data was still there)…so maybe I am reaching the limit??)

That is weird. I count the data from the terminal output to be 179 characters, so it ought to be fine. Quite mysterious! Though since it appears to only a few characters off, you might want to shorten the name of the key “deviceSubType” in the published string and see what happens.

You can also drop the blanks.

Already removed the fields I don’t need unfortunately.

I meant the blanks (aka spaces, 0x20 characters) inside your JSON.

Oh I see, thanks! :smiley:

@rickkas7 that did it! Very strange, considering there is no way I’m at the limit! I’m still getting ‘ttl’, ‘published at’, ‘coreid’ and ‘name’ fields at the end of the message from the Particle. I wouldn’t think these fields eat into the 255 byte limit, because (like you say), its 255 bytes for the publish string. I wonder whether this is a bug?

That is mysterious; I think it should work the way it was.

But in any case, you can free up even more space by making the keys in the publish JSON very short (“t”, “u”, etc.) because you can expand them to their full names in the webhook JSON definition, like:

"type":"{{t}}",
"uuid":"{{u}}"
...

It works now, using a static json string ie:

"{\"ty\" : \"alarm\", \"u\" : \"012345-ab458-2fdfg\"...

Still having an issue with using variables in this, like:

publishString = "{\"ty\":" + type + ",\"u\":" + uuid + ",\"n\":" + name +...blah blah blah 

It cuts the string short (like previously). I literally can’t think of anything that would cause this. It seems to occur in the actual string, before being sent to particle.publish(). Something in the string is causing the string to cut short.

1 Like

@joearkay, could any of your string variables (eg. uuid) contain “hidden” /n or /r characters?

Doesn’t look like it. The string cuts before this "\"testShId\"" gets added.