Web Request data includes "Invalid empty variable name"

fixed

#1

Hello,

When I try to preform a web request with a POST function I the receiving app gets “”: “Invalid empty variable name”, Can someone please let me know what I am doing wrong.

The Core Piston


#2

hey buddy,
I’m not a developer, but it looks like you are trying to post to the root webcore.co - i would imagine you need to POST or GET to a specific place (piston or webservice) - i could be wrong but not sure the piston knows exactly where its supposed to be POSTing and thus you are likely getting the error (as rejected by whoever is hosting the website).

I think it would be a good place to start with creating a piston that may look for a web request (or use IFTTT webhooks or something to send the request). When you create a piston you get a ‘piston ID’ (i think, thats just from scanning the wiki)


#3

@kevinB I tested with https://requestb.in/ and got the same result, any type of web request is getting an additional blank parameter. This appears to be a bug; I am going to recategorize the topic.

@jaburges, FYI since you will see it in other topics as well the https://webcore.co URL shown in the screenshot is just part of the anonymization of the public screenshot, the actual URL used by OP is different.


#4

Correct, the site that I am sending the request to https://requestb.in but when I take a screen shoot it changes the url to https://webcore.co


#5

@ady624, I took a look at this last night but could not figure out where the blank variable was coming from. At this line the variables list has an unexpected blank string item. This does not seem to be related to removing or renaming variables; it showed up for me with a single variable request in a scratch piston.

@kevinB does this bug break anything that you were trying to accomplish, or did you just notice and wonder why it was happening?


#6

I am trying to use WebCore to send a post to HA to have my Google Home notify me. Is there a way that I could fix this?

Thanks,
Keivn


#7

If you need to fix it you can patch your ady624 : webCoRE Piston SmartApp in the SmartThings developer panel. Edit the block starting on line 3205 from this:

for(variable in variables) {
    data  = data ?: [:]
    data[variable] = getVariable(rtData, variable).v
}

to this:

for(variable in variables) {
    if (variable) {
        data  = data ?: [:]
        data[variable] = getVariable(rtData, variable).v
    }
}

I don’t know whether this is the best way to fix this problem (i.e. where is the blank variable name coming from?), but it is a suitable workaround until a proper update is released.


#8

That worked perfect. :slight_smile:

Thank you,
Kevin


#9

I’ll look into it - any piston that can help cause the issue? I thnk a (variable in variables.findAll( !!it )) would do the job. But I want to find out what causing it… thank you


#10

Sure, run this then inspect the request at https://requestb.in/zgp0kjzg?inspect


#11

Version 0.2.0fa fixes this - please update your code with the latest version.


#12

looks like this is happening in the statement builder … whenever you select a variable or variables it adds an extra comma at the end resulting in the invalid empty variable name.

so if you select variable foo you get [foo, ]. if you select variable foo and bar you get [foo, bar, ]

guessing the statement is built when the piston is edited?

thanks!


#13

Fortunately it’s not on saving, looks like this can be resolved with a tweak at runtime. @ady624 the blank variable is being added on this line:

p = param.x + (param.xi != null ? '[' + param.xi + ']' : '');

param.x can be either a single string variable name, in which case this code works fine, or a list. In the latter case, the + operator pushes a blank string onto the list. When I change that line to p = param.x the blank web request parameter goes away (but clearly that change is not a solution).

There are at least 3 bits of code in webcore-piston that use the + operator on variables like this (grep .x + to find them). It seems worth fixing in case other issues could result from that blank variable name. @bangali can you think of a good idiomatic solution for this?


#14

Let’s see what happens with:

p = param.x instanceof List ? param.x : (param.x + (param.xi != null ? '[' + param.xi + ']' : ''));

@bangali can you please replace that line with this? Should be around line 1588.


#15

yeah that would solve it.


#16

Would or did?


#17

I’ve published that change along with @ipaterson’s pull request. :smiley: thank you, can I now work on $holidays please?


#18

Yeah that definitely works for me


#19

confirmed, it does solve it:

1aa43ddc-eb39-4528-9adb-40ba11690398 7:00:26 PM: debug variables: [test, another]

1aa43ddc-eb39-4528-9adb-40ba11690398 6:52:03 PM: debug variables: [test, another, ]


#20

Thank you @ipaterson for finding yet another bug :ashamed: